I have been trying to install the module python-magic for a few hours, and I've been encountering some problems. I am using the 32-bit version of Python 3.5.2 with 64-bit Windows 7.
First, I used the command "
pip install python-magic
C:\Program Files (x86)\Python35-32\Lib\site-packages\python_magic-0.4.12-py3.5.egg-info.
OSError: [WinError 126] The specified module could not be found
"C:\Program Files (x86)\Python35-32\Lib\site-packages\magic.dll is either not designed to run on Windows or contains an error"
"OSError: [WinError 193] %1 is not a valid Win32 application
Magic(magic_file=r'C:\Program Files (x86)\Python35-32\Lib\site-packages\python_magic-0.4.12-py3.5.egg-info\magic.exe') with the response "<magic.Magic object at 0x02EA0A70>". When I tried testing with magic.from_file(r'C:\Program Files (x86)\Python35-32\Lib\site-packages\README.txt'), though, I got the error magic.MagicException: b'could not find any magic files!
TypeError: startswith first arg must be bytes or a tuple of bytes, not str.
Did you call the 'magic' data file
magic, and leave it in the same folder as
Following your instructions I was able to reproduce the same error as you. Using Sysinternals Process Monitor, I could see that the reason for your first error appeared to be that Python was trying to load the the magic data file as if it were the library.
I then renamed the magic data file to
magic_data, restarted IDLE, and it worked. I could then use
magic to identify a file:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import magic >>> fn = r'C:\Python34\Lib\site-packages\python_magic-0.4.12-py3.4.egg-info\magic_data' >>> m = magic.Magic(magic_file=fn) >>> m.from_file(r'C:\Python34\Lib\site-packages\python_magic-0.4.12-py3.4.egg-info\zlib1.dll') 'PE32 executable for MS Windows (DLL) (console) Intel 80386 32-bit'
(I'm using a different version of Python (3.4), and a different version of Windows (10) to you, but I don't think these matter too much.)