- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在尝试安装模块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/
我已经通过 AVD 管理器启动了我的模拟器,一旦它运行,我点击了 run app。我已经等了几分钟,我的正在运行的设备出现在 选择一个正在运行的设备 中,但窗口始终保持空白。 最佳答案 您正在运行的项
我想在安装新数据库之前删除旧数据库,以便为用户更新它。 我有以下情况: 在我的 Components 部分中,我为用户提供了一个选项: [Components] Name: "updateDataba
如果我将一个 Python 模块实现为一个目录(即包),它同时具有顶级函数 run 和子模块 run,我可以指望 from example import run 总是导入函数?根据我的测试,至少在 L
我在 Eclipse Juno 上使用 Tomcat 7。我使用工作区元数据作为服务器位置(请参阅下面的我的 tomcat 配置)。 我也收到了 服务器项目在 eclipse [请看下图] 中使用单独
我正在做一些测试以了解 java 中的不同线程状态,并且遇到了一些查询。 通常,当一个线程被实例化时,它被称为处于 "NEW" 状态,然后当调用它的 start() 方法时,操作系统调度程序获得控制权
当我使用命令 npm run build -- --prod 时,我收到以下错误消息: 属性“PropertyName1”是私有(private)属性,只能在“AppComponent”类中访问 “A
我正在尝试将默认的“运行”键盘快捷键更改为 ⌘R。 - 因为我不想每次都伸手去拿触控板,而且我的手指不够长,无法一次执行⌥⇧F10。 “运行”和“运行...”有什么区别? 最佳答案 ... 用于菜单中
我现在不知道如何编写一个合适的方法来测试这种行为。请不要投反对票.. 我现在有一个 java 类负责处理数据并将数据添加到多个数据库。每个数据库都保存相同的数据,但处理方式不同(例如,以不同的插值率进
我知道不应该调用 run 方法来启动新线程执行,但我指的是 this article他们在另一个 run 方法中调用了 runnable.run(); ,这似乎暗示它启动了一个新线程或者根本没有cre
当我尝试在Windows 10/11下使用Eclipse 2023-06调试任何应用程序(甚至是hello.c)时,我总是收到以下错误:。该错误清楚地指示-(错误2)-路径是错误的。。我试图在互联网上
在运行vue文件时,需要进行npm操作,但我们发现,有时候用的是npm run serve,而有的时候用的是npm run dev,二者有什么区别 在我们运行一些 vue 项目的时候,输入npm ru
我想在 cloud run 上运行一个长时间运行的作业。该任务可能执行超过 30 分钟,并且主要发送 API 请求。cloud run 在大约 20 分钟后停止执行,从指标来看,它似乎没有识别出我的任
我们无法让 SSE 从 Google Cloud Run 上的容器发送。我已经尝试使用一个简单的 SSE 示例( https://github.com/kljensen/node-sse-exampl
直到最近,我一直在执行这个美丽来构建 + 运行一个带有堆栈的项目: stack build && .stack-work/install/x86_64-linux/lts-4.1/7.10.3/bin
我们有一个小脚本,可以抓取网页(约 17 个条目),并将它们写入 Firestore 集合。为此,我们在 Google Cloud Run 上部署了一项服务。 这段代码的执行需要大约 5 秒 when
我是Docker的新手,我知道一种运行交互式容器的方法如下: $ docker run -it image-name bash 要么 $ docker run -it image-name /bin/
Dockerfile 中的多个 RUN 条目之间有什么区别,例如: FROM php:5.6-apache RUN docker-php-ext-install mysqli RUN apt upda
对于来自文档的云运行内存使用情况 ( https://cloud.google.com/run/docs/configuring/memory-limits ) Cloud Run applicati
今天早上我更新了我的 Ubuntu 版本,现在我无法从 eclipse 运行我的应用程序。 问题是,当我单击“运行方式”时出现的列表是空的,我无法运行任何内容。 我该如何解决这个问题? 我能看到的唯一
我正在 intelliJ 上使用 livereload 测试 spring-boot-devtools。我有一个简单的 SpringBootApplication,可以正常工作。 当我从 maven
我是一名优秀的程序员,十分优秀!