Python 异常值:未能找到 libmagic。检查您在 Windows 7 中的安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18374103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:35:58  来源:igfitidea点击:

Exception Value:failed to find libmagic. Check your installation in windows 7

pythondjangodjango-admin

提问by Akhter Al Amin

When I am trying to open django admin panel this error is showing:

当我尝试打开 django 管理面板时,显示此错误:

ImportError at /admin/
failed to find libmagic.  Check your installation
Request Method: GET
Request URL:    Django Version: 1.5.1
Exception Type: ImportError
Exception Value:    failed to find libmagic.  Check your installation
Exception Location: C:\Python27\lib\site-packages\magic.py in <module>, line 131
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.2
Python Path:
['C:\Users\farhan\Downloads\dist\Django-1.5.1\django\bin\mysite',
 'C:\Python27\lib\site-packages\distribute-0.6.49-py2.7.egg',
 'C:\Windows\system32\python27.zip',
 'C:\Python27\DLLs',
 'C:\Python27\lib',
 'C:\Python27\lib\plat-win',
 'C:\Python27\lib\lib-tk',
 'C:\Python27',
 'C:\Python27\lib\site-packages',
 'C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info']
Server time:    Thu, 22 Aug 2013 13:19:01 +0600

Here is my traceback

这是我的回溯

采纳答案by dusual

Your multiuploader form uses python-magic library possibly for filetype identification. However you probably do not have all the missing dependencies installed. Please install the missing dependencies.

您的 multiuploader 表单可能使用 python-magic 库来识别文件类型。但是,您可能没有安装所有缺少的依赖项。请安装缺少的依赖项。

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

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

回答by pigsign

Install cygwin. Then move 'C:\cygwin64\bin\cygmagic-1.dll' to 'C:\Windows\System32\magic1.dll'.

安装 cygwin。然后将“C:\cygwin64\bin\cygmagic-1.dll”移动到“C:\Windows\System32\magic1.dll”。

回答by Francesco Mantovani

Go hereand then:

这里然后:

For Windoes 32bit, download the file "python_magic_bin-0.4.14-py2.py3-none-win32.whl" and run

对于Windows 32bit,下载文件“python_magic_bin-0.4.14-py2.py3-none-win32.whl”并运行

pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl

For Windows 64bit, download "python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl" and run

对于Windows 64 位,下载“python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl”并运行

pip install python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl

now python-magicworks

现在python-magic有效

enter image description here

在此处输入图片说明

EDIT: As suggested in the comments, this also works:

编辑:正如评论中所建议的,这也有效:

pip install python-magic-bin==0.4.14

回答by DebanjanB

As per the documentationthe current version of python-magicis 0.4.15

根据文档python-magic的当前版本是0.4.15

  • You can install the latest released version of python-magicthrough:

    pip install python-magic
    
  • This will install python-magic-0.4.15as follows:

    C:\Users\username>pip install python-magic
    Collecting python-magic
      Using cached https://files.pythonhosted.org/packages/42/a1/76d30c79992e3750dac6790ce16f056f870d368ba142f83f75f694d93001/python_magic-0.4.15-py2.py3-none-any.whl
    Installing collected packages: python-magic
    Successfully installed python-magic-0.4.15
    
  • In the (Windows) documentationit is mentioned:

  • 您可以通过以下方式安装最新发布的python-magic版本:

    pip install python-magic
    
  • 这将安装python-magic-0.4.15如下:

    C:\Users\username>pip install python-magic
    Collecting python-magic
      Using cached https://files.pythonhosted.org/packages/42/a1/76d30c79992e3750dac6790ce16f056f870d368ba142f83f75f694d93001/python_magic-0.4.15-py2.py3-none-any.whl
    Installing collected packages: python-magic
    Successfully installed python-magic-0.4.15
    
  • (Windows)文档中提到:

You'll need DLLs for libmagic. @julian-r has uploaded a version of this project that includes binaries to pypi: https://pypi.python.org/pypi/python-magic-bin/0.4.14

您将需要 libmagic 的 DLL。@julian-r 已将包含二进制文件的该项目的一个版本上传到 pypi:https://pypi.python.org/pypi/python-magic-bin/0.4.14

  • You can install the python-magic-bin 0.4.14through:

    pip install python-magic-bin==0.4.14
    
  • This will install python-magic-bin 0.4.14as follows:

    C:\Users\username>pip install python-magic-bin==0.4.14
    Collecting python-magic-bin==0.4.14
      Downloading https://files.pythonhosted.org/packages/5a/5d/10b9ac745d9fd2f7151a2ab901e6bb6983dbd70e87c71111f54859d1ca2e
    /python_magic_bin-0.4.14-py2.py3-none-win32.whl (397kB)
        100% |||||||||||||||||||||||||||||||||| 399kB 473kB/s
    Installing collected packages: python-magic-bin
    Successfully installed python-magic-bin-0.4.14
    
  • Sample Code:

    import magic
    print(magic.from_file("C:/Users/username/Desktop/StackOverflow/Google_Gmail.png"))
    
  • Console Output:

    PNG image data, 1366 x 768, 8-bit/color RGB, non-interlaced
    
  • 您可以通过以下方式安装python-magic-bin 0.4.14

    pip install python-magic-bin==0.4.14
    
  • 这将安装python-magic-bin 0.4.14如下:

    C:\Users\username>pip install python-magic-bin==0.4.14
    Collecting python-magic-bin==0.4.14
      Downloading https://files.pythonhosted.org/packages/5a/5d/10b9ac745d9fd2f7151a2ab901e6bb6983dbd70e87c71111f54859d1ca2e
    /python_magic_bin-0.4.14-py2.py3-none-win32.whl (397kB)
        100% |||||||||||||||||||||||||||||||||| 399kB 473kB/s
    Installing collected packages: python-magic-bin
    Successfully installed python-magic-bin-0.4.14
    
  • 示例代码:

    import magic
    print(magic.from_file("C:/Users/username/Desktop/StackOverflow/Google_Gmail.png"))
    
  • 控制台输出:

    PNG image data, 1366 x 768, 8-bit/color RGB, non-interlaced
    

回答by pijing

  1. Download cygwin. The version of cygwin must as same as python.(exp: Although your OS is Win7 x64, you still should download 32 bit cygwin because your python is 32 bit). link: https://www.cygwin.com/
  2. Install cygwin.
  3. Enter the path of cygwin and copy cygwin1.dll/cyggcc_s-1.dll/cygmagic-1.dll/cygz.dll to C:\Windows\SysWOW64.
  1. 下载 cygwin。cygwin 的版本必须和python 一样。(说明:虽然你的操作系统是Win7 x64,但你还是应该下载32 位的cygwin,因为你的python 是32 位的)。链接:https: //www.cygwin.com/
  2. 安装 cygwin。
  3. 输入cygwin的路径,将cygwin1.dll/cyggcc_s-1.dll/cygmagic-1.dll/cygz.dll复制到C:\Windows\SysWOW64。