gpt4 book ai didi

Python-magic 有 OSError : [WinError 193] error while running in 32-bit version of IDLE

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:52 25 4
gpt4 key购买 nike

我一直在尝试安装模块python-magic几个小时了,我遇到了一些问题。我在 64 位 Windows 7 上使用 32 位版本的 Python 3.5.2。

首先,我使用了命令“pip install python-magic”。我从 Files for Windows 项目下载了 magic1.dll、regex2.dll 和 zlib1.dll 以及 magic,并将这四个文件复制到

C:\Program Files (x86)\Python35-32\Lib\site-packages\python_magic-0.4.12-py3.5.egg-info.

我将上述目录添加到 Windows 环境变量中 PATH 的开头。然后我打开IDLE的Shell并输入“import magic”并得到响应OSError: [WinError 126] The specified module could not be found .

我读到“magic”文件的扩展名应该是.dll,所以我重命名了它。这导致 Windows 弹出警告 "C:\Program Files (x86)\Python35-32\Lib\site-packages\magic.dll is either not designed to run on Windows or contains an error"通过Python,"OSError: [WinError 193] %1 is not a valid Win32 application ”。我读到后一个错误是在 64 位环境中运行时经常遇到的,但我确保在 32 位 IDLE 中运行它,并且只安装了 32 位版本的 Python。

遵循previous StackOverflow posts的建议,我尝试将 cygmagic-1.dll、cygwin1.dll 和 cygz.dll 复制到 C:\Windows\System32 与 magic.dll 相同的文件夹,并且我还尝试将 cygmagic-1.dll 重命名为 magic1.dll,但这没有任何效果。我知道其他地方说你不应该混合 Cygwin Python 和 Windows Python,但我在没有这些文件参与的情况下尝试过,然后它也不起作用。

我尝试将 magic.dll 重命名为 magic.exe,这允许“导入 magic”和 magic。 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!我认为将其重命名为 magic.exe 肯定是错误的,但值得一试。

在我放弃 python-magic 之后,有人推荐了 older project 。我下载了它并将 pymagic 文件夹放在我的 site-packages 目录中。当我尝试导入 pymagic.pymagic 时,它告诉我 StringIO 模块不存在,推荐者告诉我这是因为 StringIO 来自 Python2。我将所有提到的 StringIO 更改为 io 并尝试了命令 pymagic.pymagic.identify_file(r'E:\Pictures\picture.jpg')

这生成了错误 TypeError: startswith first arg must be bytes or a tuple of bytes, not str.我对 Python 的 os、io 等模块的了解还不够,不知道如何进行修改才能使其正常工作。任何人都可以就如何让 python-magic 或 pymagic 工作或任何其他用于根据文件头识别文件的模块提出任何建议吗?我知道这个问题已经被问了很多次,但之前的答案对我来说并不适用。

最佳答案

您是否将“magic”数据文件命名为 magic,并将其与 magic1.dll 放在同一文件夹中?

按照您的指示,我能够重现与您相同的错误。使用Sysinternals Process Monitor ,我可以看到你的第一个错误的原因似乎是 Python 试图加载魔法数据文件,就好像它是库一样。

然后,我将魔法数据文件重命名为 magic_data,重新启动 IDLE,然后它就工作了。然后我可以使用 magic 来识别文件:

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'

(我使用的是不同版本的 Python (3.4) 和不同版本的 Windows (10),但我认为这些并不重要。)

关于Python-magic 有 OSError : [WinError 193] error while running in 32-bit version of IDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40702036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com