我按照这里的说明......
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
>>>
我错过了一步吗?
答案 0 :(得分:1)
python-magic
使用libmagic
,
libmagic
needs magic1.dll
,
magic1.dll
位于gnuwin32
的{{3}}包中。
解决方案1:
下载file的binaries zip
或setup
个包,并将bin
目录路径添加到PATH
环境变量。
解决方案2:
此外,代码python-magic
中有一个新的file修复了问题,您不需要gnuwin32
bin
个包{只需添加{{1} } cygwin
至PATH
}的目录,但目前在使用magic.py
或pip 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信息。