0

我在互联网上搜索了magic在 Windows 10 64 位中正确导入的解决方案。我找到了这个,但我不明白解决方案。

  1. 它说将两个 DLL 复制到操作系统中的指定路径中。

  2. 下面的命令是什么意思?

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

解决方案是1 + 2的组合吗?还是只有 1 个?我已经完成了 1. 仍然出现错误。(第一个错误已解决)

>>> 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

我得到的第二个错误

>>> 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
4

1 回答 1

1

我认为您已成功完成第 1 步。在第 2 步中,将您的 magic.mgc 文件(通过克隆libmagicwin64获得)保存在 python 脚本可访问的位置(在以下情况下为C:\Programs\libmagicwin64\文件夹)。然后你可以像这样使用......

>>> 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'
于 2017-06-11T17:59:45.137 回答