我使用pip在我的Win 7 64bit上安装了python-magic(0.4.6)。 然后我安装了cygwin 1.7.33-2以提供所需的dll并创建了一个名为magic1.dll的cygmagic-1.dll副本(参见
当我运行Python 2.7.6 32位shell时,"导入魔法"工作正常。
但是,
magic.from_file('c:\user\username\sample.txt')
给了我一个
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
任何想法是什么导致此错误以及我如何解决它? 谢谢你的帮助!
答案 0 :(得分:2)
GnuWin32 file package有一个32位的magic1.dll,以及它的依赖项regex2.dll和zlib1.dll。我从测试中知道这个版本适用于python-magic。下面概述了我在32位Python 3.3中测试它的步骤。
将文件解压缩到GnuWin32的安装目录:
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
设置环境以查找DLL和魔术文件:
C:\Temp>set PATH=%PATH%;%GNU%\bin
C:\Temp>set MAGIC=%GNU%\share\misc\magic
安装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
验证它是否有效:
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'