I installed python-magic (0.4.6) on my Win 7 64bit using pip. I then installed cygwin 1.7.33-2 to provide the needed dlls and created a copy of cygmagic-1.dll named magic1.dll (see
When I run the Python 2.7.6 32bit shell, the "import magic" works fine.
However, a
magic.from_file('c:\user\username\sample.txt')
gives me a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\magic.py", line 119, in from_file
m = _get_magic_type(mime)
File "c:\Python27\lib\site-packages\magic.py", line 107, in _get_magic_type
i = instances.__dict__[mime] = Magic(mime=mime)
File "c:\Python27\lib\site-packages\magic.py", line 55, in __init__
self.cookie = magic_open(flags)
WindowsError: exception: access violation writing 0x00000000
Any ideas what causes the this error and how I can fix it? Thank you for your help!
The GnuWin32 file package has a 32-bit magic1.dll, along with its dependencies regex2.dll and zlib1.dll. I know from testing that this version works with python-magic. Here's an overview of the steps that I took to test this in 32-bit Python 3.3.
Extract the files to GnuWin32's installation directory:
C:\Temp>set "GNU=C:\Program Files (x86)\GNU"
C:\Temp>7z x -y -o"%GNU%" file-5.03-bin.zip > nul
C:\Temp>7z x -y -o"%GNU%" file-5.03-dep.zip > nul
Set up the environment to find the DLLs and magic file:
C:\Temp>set PATH=%PATH%;%GNU%\bin
C:\Temp>set MAGIC=%GNU%\share\misc\magic
Install python-magic:
C:\Temp>py -3.3-32 -m pip install python-magic
Collecting python-magic
Downloading python-magic-0.4.6.tar.gz
Installing collected packages: python-magic
Running setup.py install for python-magic
Successfully installed python-magic-0.4.6
Verify that it works:
C:\Temp>py -3.3-32
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:37:12)
[MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, magic
>>> magic.from_file(sys.executable)
b'PE32 executable for MS Windows (console) Intel 80386 32-bit'