Missing files for `magic` library on Windows

后端 未结 3 1590
栀梦
栀梦 2020-12-31 14:11

I need to get mime type for some files on windows, so i\'ve installed python-magic (on 32-bit python 2.7.3).
It depends on unix magic library.<

相关标签:
3条回答
  • 2020-12-31 14:55

    As the python-magic problems seems to be quite common, here a working solution fo future googlers: After testing most solutions without altering the source-code, I found the following to get python-magic working out of the box:

    1. Install GnuWin32 file first
    2. Set the environment variable MAGIC=path\to\gnuwin32\share\misc\magic
    3. Assure all installed executables/libraries to be accessible via the PATH
    4. Install python-magic via pip
    0 讨论(0)
  • 2020-12-31 14:59

    Path to magic file has to be explicitly passed to the constructor.

    magic_object = magic.Magic(magic_file = 'path_to_magic_files/magic'))
    
    0 讨论(0)
  • 2020-12-31 15:05

    For future google visitors: Another solution is setting the %MAGIC% enviroment variable in the systems setting to point to the magic file, for me it was:

    "c:\Program Files (x86)\GnuWin32\share\misc\magic"
    

    No need to hardcode the path in your program!

    0 讨论(0)
提交回复
热议问题