Python 错误:文件 5.3 仅支持版本 7 魔术文件 [英] Python Error : File 5.3 supports only version 7 magic file

查看:20
本文介绍了Python 错误:文件 5.3 仅支持版本 7 魔术文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用magic1.dll、regex2.dll和zlib1.dll文件安装了python-magic并且它正确导入但是当我尝试做例如m = magic.Magic()时我得到错误:找不到任何魔法文件.所以,我用谷歌搜索了一下,找到了答案此处 给了我另一个错误:文件 5.3 仅支持版本 7 魔术文件.magic.mgc"是版本 12.

我可以获得魔法文件版本 7 吗?

解决方案

我搜索了很多解决这个问题的方法,但没有找到.我有点玩魔术文件,突然它起作用了.因此,现在我将编写一个分步指南,为 Windows 和 Linux 用户解决类似我的或类似我的问题.

对于 WINDOWS:

步骤 1: 从您的 python lib 文件夹中删除 magic.pymagic.pyc 文件.如果你下载了zlib1.dllmagic1.dllregex2.dllmagic.mgc,也要删除

第 2 步:下载这个 zip 文件 并提取它.

注意: 这个 zip 文件包含我们需要的所有内容:magic.py ,magic.pycmagic.mgczlib1.dllmagic.dllregex2.dll.

第 3 步: 然后将 magic.pymagic.pyc 和 DLL 文件移动到 python lib 文件夹中.

步骤 4: 转至计算机属性 > 高级系统设置 > 环境变量,然后单击 New....在变量名中输入:magic 在另一个字段中输入 magic.mgc 文件的路径,然后按确定.

现在应该可以了:

<预><代码>>>>进口魔法>>>s = magic.Magic()>>>s.from_file("test.txt")'ASCII 文本,没有行终止符'>>>

注意: 如果您将程序编译为 EXE,请确保 DLL 文件和 magic.mgc 位于与您的 EXE 程序相同的文件夹才能正常工作.如果你不这样做,你会得到错误

<小时>

对于 LINUX:

如果您是 Linux 用户并且对魔法有疑问,请执行以下操作:

步骤 1: 在命令行中,输入 sudo pip install python-magic 以安装或升级到最新版本的 python-magic.如果您遇到 IncompleteRead 错误,请在命令行中输入:

对于 Python 2:

<块引用>

sudo apt-get 删除 python-pip &&须藤easy_install pip

对于 Python 3:

<块引用>

sudo apt-get 删除 python3-pip &&须藤easy_install3 pip

这将以某种方式升级您的 pip 并消除错误.完成后,在pip升级后输入sudo pip install python-magic来安装magic.

那么它应该可以工作:

<预><代码>>>>进口魔法>>>s = magic.Magic()>>>s.from_file("test.txt")'ASCII 文本,没有行终止符'>>>

I installed python-magic with magic1.dll, regex2.dll, and zlib1.dll files and it imports correctly but when I try to do for example m = magic.Magic() I get the error : Could not find any magic file.So, I googled a little bit and found an answer here that gave me another error : File 5.3 supports only version 7 magic file. "magic.mgc" is version 12.

Can I get a magic file version 7 ?

解决方案

I searched a lot for a solution for this problem, but couldn't found. I was a little bit playing with magic files and suddenly it worked. So now I will write a step-by-step to resolve problems like mine or similar to mine for Windows and Linux Users.

FOR WINDOWS:

Step 1: Delete the magic.py and the magic.pyc files from your python lib folder. And if you downloaded zlib1.dll, magic1.dll, regex2.dll and magic.mgc, also delete them.

Step 2: Download this zip file and extract it.

Note : This zip file contains all what we need : magic.py ,magic.pyc, magic.mgc, zlib1.dll, magic.dll and regex2.dll.

Step 3: Then move magic.py ,magic.pyc and the DLL files to the python lib folder.

Step 4: Go to Computer Properties > Advanced System Settings > Environment Variables, and click on New.... In the variable name type : magic And in the other field enter the path to the magic.mgc file and press Ok.

And Now It Should Work:

>>> import magic
>>> s = magic.Magic()
>>> s.from_file("test.txt")
'ASCII text, with no line terminators'
>>> 

Note : If you compile your program to EXE, make sure that the DLL files and magic.mgc are in the same folder as your EXE program to work properly. If you don't do that you will get errors


FOR LINUX:

If you are a Linux user and you have problems with magic, here are what you have to do:

Step 1: In your command line, type sudo pip install python-magic to install or to upgrade to the lastest version of python-magic. If you have the IncompleteRead error, then type in your command line:

For Python 2:

sudo apt-get remove python-pip && sudo easy_install pip

For Python 3:

sudo apt-get remove python3-pip && sudo easy_install3 pip

This will upgrade in a certain way your pip and remove the error. After it finished, type sudo pip install python-magic to install magic after the pip upgrade.

Then It should Work:

>>> import magic
>>> s = magic.Magic()
>>> s.from_file("test.txt")
'ASCII text, with no line terminators'
>>> 

这篇关于Python 错误:文件 5.3 仅支持版本 7 魔术文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆