我按照这里的说明操作...
https://github.com/ahupp/python-magic#dependencies
我运行了pip安装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:Python27libsite-packagesmagic.py", line 161, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
>>>
我错过了一步吗?
python-magic
使用libmagic
,
libmagic
需要magic1.dll
,
该magic1.dll
在gnuwin32
的文件包中。
解决方案 1:
下载binaries zip
或setup
文件包,并将其目录bin
路径添加到PATH
环境变量中。
解决方案 2:
python-magic
代码中还有一个新的更改集可以解决问题,您无需归档gnuwin32
包(只需将cygwin
目录添加到PATH
bin
),但目前还没有magic.py
,而您使用pip install python-magic
或pip install python-magic --upgrade
安装它,
因此,您需要从主安装python-magic
。
也看看这篇文章:http://www.thehackeruniversity.com/2014/02/02/obtain-python-mime-types-windows/
这家伙使用 Hachoir 来查找二进制文件的 mime 信息。