How to / File Magic¶
Legacy Wiki Page
This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.
General Information¶
Today == Saturday, October 25, 2008
With special thanks for many of The Keys to frank and his blog. Also, an IBM article on setuptools had the info that helped me (at least) âinstallâ setuptools without easy_install. (Necessary Today for Py v2.6; see below.)
I tried with Python v2.6, but could not get it to work; Iâm still not familiar with the magic of eggs, distutils, setuptools, etc. If anyone has the fix(es), let me know and Iâll retest, revise, and update this info! (FYI: The problem is itâs acting as if it canât find magic1.dll; if v2.6 is uninstalled, v2.5[.2] is [re-]installed, all works A-OK.)
This is my NON-PRISTINE copy of SWIG-able python-magic, unless/until Mr. Hupp re-posts it to his site (see below): LARZ-python-magic-v0.1-c112ac064b7f.zip
NOTE: Mr. Hupp is working on a newer version; thus, all of this may become depreciatedâŠ
This is what I did. It works on (32-bit) Windows XP Pro, SP3, on an old Athlon system with <=512MB.
As they say: Your Mileage May Vary⊠đ
-Larry Hale (pythonlarry ta gmail)
Software Used/Needed¶
CygWin¶
version 2.573.2.3
May setup with all default settings, except MUST ADD
Devel (group)
gcc (3.4.4-3)
gcc-core (3.4.4-3) (should auto-select)
gcc-g++ (3.4.4-3) (should auto-select)
gcc-mingw (20040810-1)
gcc-mingw-core (20050522-1) (should auto-select)
gcc-mingw-g++ (20080522-1) (should auto-select)
make (3.81-2)
SWIG (1.3.36-1)
GnuWin32 - (Magic) âFileâ Utility¶
version 4.26 (more recent than what was available via CygWin Today)
http://gnuwin32.sourceforge.net/packages/file.htm
http://downloads.sourceforge.net/gnuwin32/file-4.26-setup.exe
May setup with defaults, except (I recommend) change install directory from
GnuWin32\File
to simply
File
NOTE: Itâs already set to install below âProgram Filesâ
Python¶
version 2.5.2
http://python.org/ftp/python/2.5.2/python-2.5.2.msi
Installed with all default settings EXCEPT install-to path
C:\Program Files\Python25
(Python) setuptools¶
version 0.6c9
http://pypi.python.org/pypi/setuptools
As of Today there wasnât a pre-built .EXE installer for Python 2.6 (which Iâd TRIED to test with first, to no avail), SO had to âhackâ a bit - see IBM article link, above, for some info⊠simply grab
and run
python ez_setup.py
Otherwise, if an installer is avail for your ver of Py, use it! đ
python-magic¶
version â0.1â (c112ac064b7f) with/for SWIG
http://hupp.org/adam/hg/python-magic
NOTE: Adam (Hupp) doesnât have the SWIG version posted any longer; my copy isnât âpristineâ; anybody have one lying around to send me? đ
Configuration & Changes¶
C:\Program Files\Python25\Lib\distutils¶
distutils.cfg¶
must have thiw file, with at least
{{{[build] compiler = mingw32}}}
version.py¶
Due to newer CygWin, change line 100 from
{{{version_re = re.compile(râ^(\d+) . (\d+) (. (\d+))? ([ab](\d+))?$â,
}}} to
{{{version_re = re.compile(râ^(\d+) . (\d+) (. (\d+))? (. (\d+))?$â,
}}}
Do The Installation Shuffle¶
Go to where youâve put the python-magic source files, then:
{{{path=%PATH%;C:\Program Files\Python25;C:\cygwin\bin;C:\Program Files\File\bin
python setup.py install}}}
Examples of Output You Might See¶
No setuptools¶
{{{Traceback (most recent call last):
File âsetup.pyâ, line 1, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools}}}
UNSUCCESSFUL build, due to no distutils.cfg compiler=mingw32 âfixâ¶
{{{running install running bdist_egg running egg_info creating magic.egg-info writing magic.egg-info\PKG-INFO writing top-level names to magic.egg-info\top_level.txt writing dependency_links to magic.egg-info\dependency_links.txt writing manifest file âmagic.egg-info\SOURCES.txtâ reading manifest file âmagic.egg-info\SOURCES.txtâ writing manifest file âmagic.egg-info\SOURCES.txtâ installing library code to build\bdist.win32\egg running install_lib running build_py copying magic.py -> build\lib.win32-2.5 copying cmagic.py -> build\lib.win32-2.5 running build_ext error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing â-c mingw32â to setup.py.}}}
UNSUCCESSFUL build, due to the new CygWin meets the OLD/default distutils\version.py regex (line 100)¶
{{{running install running bdist_egg running egg_info writing magic.egg-info\PKG-INFO writing top-level names to magic.egg-info\top_level.txt writing dependency_links to magic.egg-info\dependency_links.txt reading manifest file âmagic.egg-info\SOURCES.txtâ writing manifest file âmagic.egg-info\SOURCES.txtâ installing library code to build\bdist.win32\egg running install_lib running build_py running build_ext Traceback (most recent call last):
File âsetup.pyâ, line 12, in <module>
libraries=[âmagicâ])],
File âC:\Program Files\Python25\lib\distutils\core.pyâ, line 151, in setup
dist.run_commands()
File âC:\Program Files\Python25\lib\distutils\dist.pyâ, line 974, in run_commands
self.run_command(cmd)
File âC:\Program Files\Python25\lib\distutils\dist.pyâ, line 994, in run_command
cmd_obj.run()
File âC:\Program Files\Python25\lib\site-packages\setuptools-0.6c9-py2.5.egg\setuptools\command\install.pyâ, line 76, in run File âC:\Program Files\Python25\lib\site-packages\setuptools-0.6c9-py2.5.egg\setuptools\command\install.pyâ, line 96, in do_egg_install
etc., etc., etc. âŠ
File âC:\Program Files\Python25\lib\distutils\version.pyâ, line 107, in parse
raise ValueError, âinvalid version number â%sââ % vstring
ValueError: invalid version number â2.18.50.20080625â}}}
Successful Build¶
{{{running install running bdist_egg running egg_info writing magic.egg-info\PKG-INFO writing top-level names to magic.egg-info\top_level.txt writing dependency_links to magic.egg-info\dependency_links.txt reading manifest file âmagic.egg-info\SOURCES.txtâ writing manifest file âmagic.egg-info\SOURCES.txtâ installing library code to build\bdist.win32\egg running install_lib running build_py running build_ext creating build\bdist.win32 creating build\bdist.win32\egg copying build\lib.win32-2.5\cmagic.py -> build\bdist.win32\egg copying build\lib.win32-2.5\magic.py -> build\bdist.win32\egg copying build\lib.win32-2.5\_cmagic.pyd -> build\bdist.win32\egg byte-compiling build\bdist.win32\egg\cmagic.py to cmagic.pyc byte-compiling build\bdist.win32\egg\magic.py to magic.pyc creating stub loader for _cmagic.pyd byte-compiling build\bdist.win32\egg\_cmagic.py to _cmagic.pyc creating build\bdist.win32\egg\EGG-INFO copying magic.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO copying magic.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO copying magic.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO copying magic.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO writing build\bdist.win32\egg\EGG-INFO\native_libs.txt zip_safe flag not set; analyzing archive contents⊠creating dist creating âdist\magic-0.1-py2.5-win32.eggâ and adding âbuild\bdist.win32\eggâ to it removing âbuild\bdist.win32\eggâ (and everything under it) Processing magic-0.1-py2.5-win32.egg Removing c:\program files\python25\lib\site-packages\magic-0.1-py2.5-win32.egg Copying magic-0.1-py2.5-win32.egg to c:\program files\python25\lib\site-packages magic 0.1 is already the active version in easy-install.pth
Installed c:\program files\python25\lib\site-packages\magic-0.1-py2.5-win32.egg Processing dependencies for magic==0.1 Finished processing dependencies for magic==0.1}}}
NOTE: Actually, this is what youâll see if youâve successfully RE-compiled⊠but I digressâŠ
Usage Notes¶
{{{Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type âhelpâ, âcopyrightâ, âcreditsâ or âlicenseâ for more information. >>> import magic}}}
magic1.dll Not in Path¶
FIRST: Windows msgbox with red-X icon and [OK] button:
TITLE: python.exe - Unable To Locate Component
TEXT: This application has failed to start because magic1.dll was not found. Re-installing the application may fix this problem.
THEN (back in interpreter): {{{Traceback (most recent call last):
File â<stdin>â, line 1, in <module> File âbuild\bdist.win32\egg\magic.pyâ, line 2, in <module> File âbuild\bdist.win32\egg\cmagic.pyâ, line 5, in <module> File âbuild\bdist.win32\egg\_cmagic.pyâ, line 7, in <module> File âbuild\bdist.win32\egg\_cmagic.pyâ, line 6, in [bootstrap]
ImportError: DLL load failed: The specified module could not be found.}}}
NOTE: This is the same exact message (inside interpreter, NOT a Windows msgbox) that shows when I tried to use Py v2.6.
Successful Import/Use¶
{{{>>> import magic >>> test = magic.Magic() >>> test.from_file( â\cygwin\bin\which.exeâ ) âPE32 executable for MS Windows (console) Intel 80386 32-bitâ}}}
Magic (Compiled) Files Not in Path/Elsewhere¶
{{{>>> import magic >>> test = magic.Magic( magic_file = âC:\magicâ ) # NOTE: This is the full path+filename of the magic db file >>> test.from_file( â\startrek.exeâ ) âMS-DOS executable, MZ for MS-DOSâ}}}
File Location Information¶
DEFAULT/ASSUMED LOCATION FOR MAGIC DATABASE FILES IS C:\Program Files\File\share\file
NOTE: magic1.dll file MUST BE FINDABLE IN THE PATH!!!