运行 PyInstaller 生成的二进制文件时出现模块导入错误

2024-01-20

我在 RHEL X64 上尝试使用 PyInstaller 执行简单的 hello.py 时遇到错误。

Python 2.7.12 安装在 /opt/python 中

编译输出:

[root@myrig CommandManager]# pyinstaller Hello.py
21 INFO: PyInstaller: 3.2
21 INFO: Python: 2.7.12
22 INFO: Platform: Linux-3.10.0-327.22.2.el7.x86_64-x86_64-with-redhat-7.2-Maipo
62 INFO: wrote /home/myuser/CommandManager/Hello.spec
66 INFO: UPX is not available.
107 INFO: Extending PYTHONPATH with paths
['/home/myuser/CommandManager', '/home/myuser/CommandManager']
107 INFO: checking Analysis
108 INFO: Building Analysis because out00-Analysis.toc is non existent
108 INFO: Initializing module dependency graph...
110 INFO: Initializing module graph hooks...
148 INFO: running Analysis out00-Analysis.toc
155 INFO: Caching module hooks...
158 INFO: Analyzing /home/myuser/CommandManager/Hello.py
160 INFO: Loading module hooks...
161 INFO: Loading module hook "hook-encodings.py"...
1493 INFO: Looking for ctypes DLLs
1493 INFO: Analyzing run-time hooks ...
1500 INFO: Looking for dynamic libraries
1801 INFO: Looking for eggs
1801 INFO: Python library not in binary depedencies. Doing additional searching...
1827 INFO: Using Python library /lib64/libpython2.7.so.1.0
1899 INFO: Warnings written to /home/myuser/CommandManager/build/Hello/warnHello.txt
1983 INFO: checking PYZ
1983 INFO: Building PYZ because out00-PYZ.toc is non existent
1983 INFO: Building PYZ (ZlibArchive) /home/myuser/CommandManager/build/Hello/out00-PYZ.pyz
2465 INFO: checking PKG
2465 INFO: Building PKG because out00-PKG.toc is non existent
2465 INFO: Building PKG (CArchive) out00-PKG.pkg
2648 INFO: Bootloader /opt/python/lib/python2.7/site-packages/PyInstaller/bootloader/Linux-64bit/run
2648 INFO: checking EXE
2649 INFO: Building EXE because out00-EXE.toc is non existent
2649 INFO: Building EXE from out00-EXE.toc
2690 INFO: Appending archive to ELF section in EXE /home/myuser/CommandManager/build/Hello/Hello
2991 INFO: checking COLLECT
2992 INFO: Building COLLECT because out00-COLLECT.toc is non existent
2993 INFO: Building COLLECT out00-COLLECT.toc

你好.py:

print("Hello")

这是我收到的错误:

mod is NULL - structTraceback (most recent call last):
  File "/opt/python/lib/python2.7/struct.py", line 1, in <module>
    from _struct import *
ImportError: /home/myuser/CommandManager/dist/Hello/_struct.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
mod is NULL - pyimod02_archiveTraceback (most recent call last):
  File "/tmp/pip-build-xDjNbD/pyinstaller/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
ImportError: No module named struct
mod is NULL - pyimod03_importersTraceback (most recent call last):
  File "/tmp/pip-build-xDjNbD/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
ImportError: No module named pyimod02_archive
Traceback (most recent call last):
  File "site-packages/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ImportError: No module named pyimod03_importers
Failed to execute script pyiboot01_bootstrap

任何线索可能是什么原因造成的?

自动生成的 Hello.spec 文件如下所示:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['Hello.py'],
             pathex=['/home/myuser/CommandManager'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='Hello',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='Hello')

PyInstaller 需要使用 python 来编译--enable-shared and LDFLAGS=-Wl,-rpath=<path to python lib>.

就我而言:

./configure --enable-shared --prefix=/opt/python LDFLAGS=-Wl,-rpath=/opt/python/lib

附加参考:https://bugs.python.org/issue27685 https://bugs.python.org/issue27685

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

运行 PyInstaller 生成的二进制文件时出现模块导入错误 的相关文章

  • Django 代理模型的继承和多态性

    我正在开发一个我没有启动的 Django 项目 我面临着一个问题遗产 我有一个大模型 在示例中简化 称为MyModel这应该代表不同种类的物品 的所有实例对象MyModel应该具有相同的字段 但方法的行为根据项目类型的不同而有很大差异 到目
  • 将 saxon 与 python 结合使用

    我需要使用 python 处理 XSLT 目前我正在使用仅支持 XSLT 1 的 lxml 现在我需要处理 XSLT 2 有没有办法将 saxon XSLT 处理器与 python 一起使用 有两种可能的方法 设置一个 HTTP 服务 接受
  • 使 django 服务器可以在 LAN 中访问

    我已经安装了Django服务器 可以如下访问 http localhost 8000 get sms http 127 0 0 1 8000 get sms 假设我的IP是x x x x 当我这样做时 从同一网络下的另一台电脑 my ip
  • Python(Selenium):如何通过登录重定向/组织登录登录网站

    我不是专业程序员 所以请原谅任何愚蠢的错误 我正在做一些研究 我正在尝试使用 Selenium 登录数据库来搜索大约 1000 个术语 我有两个问题 1 重定向到组织登录页面后如何使用 Selenium 登录 2 如何检索数据库 在我解决
  • 使用 matplotlib 绘制时间序列数据并仅在年初显示年份

    rcParams date autoformatter month b n Y 我正在使用 matpltolib 来绘制时间序列 如果我按上述方式设置 rcParams 则生成的图会在每个刻度处标记月份名称和年份 我怎样才能将其设置为仅在每
  • 使用 on_bad_lines 将 pandas.read_csv 中的无效行写入文件

    我有一个 CSV 文件 我正在使用 Python 来解析该文件 我发现文件中的某些行具有不同的列数 001 Snow Jon 19801201 002 Crom Jake 19920103 003 Wise Frank 19880303 l
  • 以编程方式停止Python脚本的执行? [复制]

    这个问题在这里已经有答案了 是否可以使用命令在任意行停止执行 python 脚本 Like some code quit quit at this point some more code that s not executed sys e
  • Python pickle:腌制对象不等于源对象

    我认为这是预期的行为 但想检查一下 也许找出原因 因为我所做的研究结果是空白 我有一个函数可以提取数据 创建自定义类的新实例 然后将其附加到列表中 该类仅包含变量 然后 我使用协议 2 作为二进制文件将该列表腌制到文件中 稍后我重新运行脚本
  • Flask如何获取请求的HTTP_ORIGIN

    我想用我自己设置的 Access Control Allow Origin 标头做出响应 而弄清楚请求中的 HTTP ORIGIN 参数在哪里似乎很混乱 我在用着烧瓶 0 10 1 以及HTTP ORIGIN似乎是这个的特点之一object
  • 在Python中获取文件描述符的位置

    比如说 我有一个原始数字文件描述符 我需要根据它获取文件中的当前位置 import os psutil some code that works with file lp lib open path to file p psutil Pro
  • 如何使用Python创建历史时间线

    So I ve seen a few answers on here that helped a bit but my dataset is larger than the ones that have been answered prev
  • Pygame:有没有简单的方法可以找到按下的任何字母数字的字母/数字?

    我目前正在开发的游戏需要让人们以自己的名义在高分板上计时 我对如何处理按键有点熟悉 但我只处理过寻找特定的按键 有没有一种简单的方法可以按下任意键的字母 而不必执行以下操作 for event in pygame event get if
  • 在f字符串中转义字符[重复]

    这个问题在这里已经有答案了 我遇到了以下问题f string gt gt gt a hello how to print hello gt gt gt f a a gt gt gt f a File
  • 无法在 Python 3 中导入 cProfile

    我试图将 cProfile 模块导入 Python 3 3 0 但出现以下错误 Traceback most recent call last File
  • Jupyter Notebook 内核一直很忙

    我已经安装了 anaconda 并且 python 在 Spyder IPython 等中工作正常 但是我无法运行 python 笔记本 内核被创建 它也连接 但它始终显示黑圈忙碌符号 防火墙或防病毒软件没有问题 我尝试过禁用两者 我也无法
  • 使用 Python 绘制 2D 核密度估计

    I would like to plot a 2D kernel density estimation I find the seaborn package very useful here However after searching
  • 绘制与Fig.show()内联的IPython Notebook图形?

    我正在使用 IPython Notebook 调用内联模式 pylab inline 以下代码立即在单元格处绘制一个图形 fig plt figure axes fig add axes 0 0 1 1 不过 我想在一个单元格中创建绘图 轴
  • 从列表指向字典变量

    假设你有一个清单 a 3 4 1 我想用这些信息来指向字典 b 3 4 1 现在 我需要的是一个常规 看到该值后 在 b 的位置内读写一个值 我不喜欢复制变量 我想直接改变变量b的内容 假设b是一个嵌套字典 你可以这样做 reduce di
  • 如何将输入读取为数字?

    这个问题的答案是社区努力 help privileges edit community wiki 编辑现有答案以改进这篇文章 目前不接受新的答案或互动 Why are x and y下面的代码中使用字符串而不是整数 注意 在Python 2
  • NotImplementedError:无法将符号张量 (lstm_2/strided_slice:0) 转换为 numpy 数组。时间

    张量流版本 2 3 1 numpy 版本 1 20 在代码下面 define model model Sequential model add LSTM 50 activation relu input shape n steps n fe

随机推荐