3

I want to use Python-Magic library, but I get:

magic.magic.MagicException: b'could not find any valid magic files!'

Error on a simple code like this:

filepath = 'path\\somefile.txt'
print(magic.from_file(filepath))

I did google the error message and I tried this; as mentioned Missing files for `magic` library on Windows

magic_object = magic.Magic(magic_file = 'C:\\Program Files (x86)\\GnuWin32\\share\\misc\\magic')

This time I get this error:

magic.magic.MagicException: b"File 5.32 supports only version 14 magic files. `C:\Program Files (x86)\GnuWin32\share\misc\magic.mgc' is version 7"

I also did this; Python Error : File 5.3 supports only version 7 magic file nothing changes.

Also I tried changing environment variableMAGIC=path\to\gnuwin32\share\misc\magic and downloading http://gnuwin32.sourceforge.net/packages/file.htm and nothing changes.

Thanks in advance,

MertTheGreat
  • 500
  • 1
  • 7
  • 20
  • 2
    This may not be your problem, but [never use unescaped backslashes in non-raw string literals for Windows pathnames](https://stackoverflow.com/questions/2953834/windows-path-in-python). – abarnert Apr 01 '18 at 20:28
  • @abarnert I actually use 'os.path' and it works for other lines of codes. – MertTheGreat Apr 01 '18 at 20:33
  • change the path to some other literal path with `\test` in it you'll see the issue. – Jean-François Fabre Apr 01 '18 at 20:36
  • I don’t know what you mean by that, but unescaped backslashes in pathname strings are wrong before it even gets to `os.path`. For example, the string `’\b’` is a single backspace, not a backslash and a `b`. With many letters you will get lucky, but you shouldn’t rely on getting lucky. Just escape them, use a raw string literal, or use forward slashes. – abarnert Apr 01 '18 at 20:37
  • @Jean-FrançoisFabre do you mean like `C:\Users\MertTheGreat\Desktop\somefile.txt` because the path is something like that. – MertTheGreat Apr 01 '18 at 20:40
  • `\U` will fail in python 3 (unicode escape). – Jean-François Fabre Apr 01 '18 at 20:40

0 Answers0