Sabari
Sabari

Reputation: 1

Problems importing magic on Windows 64-bit

I have searched on the internet for a solution to import magic correctly in Windows 10 64-bit. I found this, but I do not understand the solution.

  1. It says to copy two DLLs into the specified path in the OS.

  2. What does the below command mean?

    file_magic = magic.Magic(magic_file="c:\path\to\magic.mgc")
    

Is the solution the combination of 1 + 2? Or just 1? I have done 1. Still getting an error. (the 1st error is solved)

>>> import magic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\magic.py", line 176, in <modu
  raise ImportError('failed to find libmagic.  Check your install
ImportError: failed to find libmagic.  Check your installation

Second Error I am getting

>>> import magic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\magic\__init__.py", line 1, in <module>
    from . import ffi
  File "C:\Python27\lib\site-packages\magic\ffi.py", line 27, in <module>
    ext_package="magic")
  File "C:\Python27\lib\site-packages\cffi\api.py", line 437, in verify
    lib = self.verifier.load_library()
  File "C:\Python27\lib\site-packages\cffi\verifier.py", line 113, in        load_library
    self._compile_module()
  File "C:\Python27\lib\site-packages\cffi\verifier.py", line 210, in _compile_module
    outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
  File "C:\Python27\lib\site-packages\cffi\ffiplatform.py", line 29, in compile
    outputfilename = _build(tmpdir, ext, compiler_verbose)
  File "C:\Python27\lib\site-packages\cffi\ffiplatform.py", line 55, in _build
    dist.run_command('build_ext')
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
  File "C:\Python27\lib\site-packages\setuptools\command\build_ext.py", line 75, in run
_build_ext.run(self)
  File "C:\Python27\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
  File "C:\Python27\lib\distutils\command\build_ext.py", line 449, in build_extensions
self.build_extension(ext)
  File "C:\Python27\lib\site-packages\setuptools\command\build_ext.py", line 196, in build_extension
_build_ext.build_extension(self, ext)
  File "C:\Python27\lib\distutils\command\build_ext.py", line 499, in build_extension
depends=ext.depends)
  File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile
self.initialize()
  File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\Python27\lib\site-packages\setuptools\msvc.py", line 136, in msvc9_query_vcvarsall
return EnvironmentInfo(arch, ver).return_env()
  File "C:\Python27\lib\site-packages\setuptools\msvc.py", line 1097, in return_env
[self.VCIncludes,
  File "C:\Python27\lib\site-packages\setuptools\msvc.py", line 805, in VCIncludes
return [os.path.join(self.si.VCInstallDir, 'Include'),
  File "C:\Python27\lib\site-packages\setuptools\msvc.py", line 542, in VCInstallDir
    raise distutils.errors.DistutilsPlatformError(msg)
 distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 9.0 is required.     Get it from http://aka.ms/vcpython27

Upvotes: 0

Views: 2492

Answers (1)

Banee Ishaque K
Banee Ishaque K

Reputation: 578

I think you are successfully completed Step 1. In 2nd step keep your magic.mgc file ( obtained by cloning of libmagicwin64) somewhere accessible by python script ( in the below case C:\Programs\libmagicwin64\ folder). then you can use like this...

>>> import magic
>>> file_magic = magic.Magic(magic_file="C:\Programs\libmagicwin64\magic.mgc")
>>> print(file_magic.from_file("D:\Work Folder\mcabcaaug2016.pdf"))
'PDF document, version 1.4'

Upvotes: 1

Related Questions