【问题标题】:error message using python magic on Windows XP在 Windows XP 上使用 python magic 的错误消息
【发布时间】:2014-01-24 21:10:57
【问题描述】:

我按照这里的说明...

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
>>>

我错过了一步吗?

【问题讨论】:

  • 您是否将 cygwin1.dll、cygz.dll 和 cygmagic-1.dll 复制到 C:\Windows\System32?如果您没有在 Cygwin 中运行 Python,则可能需要这样做。
  • @MattDMo:事实上,它在文档中明确指出,就在他链接的部分……
  • @abarnert - 对。我只是问,因为 OP 没有在问题中明确提到它。
  • @MattDMo:是的,这就是我为你的评论 +1 的原因。

标签: python python-magic


【解决方案1】:

python-magic 使用 libmagic

libmagicneedsmagic1.dll

magic1.dllgnuwin32file 包中。

解决方案一:

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

解决方案 2:

还有一个新的change-setpython-magic 的代码中解决了这个问题,你不需要gnuwin32file 包(只需将cygwinbin 目录添加到@987654341 @),但当您使用 pip install python-magicpip install python-magic --upgrade 安装它时,magic.py 中目前还没有,
所以你需要从master安装python-magic

【讨论】:

    【解决方案2】:

    也可以看看这个帖子:http://www.thehackeruniversity.com/2014/02/02/obtain-python-mime-types-windows/

    这家伙使用 Hachoir 来查找二进制文件的 mime 信息。

    【讨论】:

      猜你喜欢
      • 2011-10-01
      • 2018-06-01
      • 1970-01-01
      • 2013-09-17
      • 1970-01-01
      • 2011-07-21
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多