在Windows XP上使用python magic的错误消息

时间:2014-01-24 21:10:58

标签: python python-magic

我按照这里的说明......

https://github.com/ahupp/python-magic#dependencies

我运行pip install python-magic并且安装没有任何问题。然后我安装了cygwin并将C:\ cygwin \ bin添加到我的系统路径中。当我在Windows命令提示符下运行python解释器并导入魔术时,我收到此错误...

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\magic.py", line 161, in <module>
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation
>>>

我错过了一步吗?

2 个答案:

答案 0 :(得分:1)

python-magic使用libmagic

libmagic needs magic1.dll

magic1.dll位于gnuwin32的{​​{3}}包中。

解决方案1:

下载filebinaries zipsetup个包,并将bin目录路径添加到PATH环境变量。

解决方案2:

此外,代码python-magic中有一个新的file修复了问题,您不需要gnuwin32 bin个包{只需添加{{1} } cygwinPATH}的目录,但目前在使用magic.pypip install python-magic进行安装时pip install python-magic --upgrade尚未进行,{br> > 因此,您需要从change-set安装python-magic

答案 1 :(得分:0)

另请看这篇文章:http://www.thehackeruniversity.com/2014/02/02/obtain-python-mime-types-windows/

这个人使用Hachoir找到二进制文件的mime信息。