python - pyInstaller 可执行文件在 Ubuntu 12.04 Precise 上缺少模块 "_struct"

标签 python module pyinstaller

我想将我的 python 项目打包成 UNIX 可执行文件。为此,我尝试了 py2exe、cxfreeze 和 pyInstaller,但没有任何效果。希望你能帮助我使用 pyinstaller。所以这里是:

我已经从 http://www.pyinstaller.org/ 下载了 pyinstaller-2.0 的 zip 文件并解压缩。

在文件夹中,我运行 python pyinstaller.py ../helloworld.py(输出列在末尾)。

然后我尝试执行文件:./helloworld/dist/helloworld/helloworld 这给了我输出:

mod is NULL - structTraceback (most recent call last):
  File "/usr/lib/python2.7/struct.py", line 1, in <module>
    from _struct import *
ImportError: No module named _struct
mod is NULL - archiveTraceback (most recent call last):
  File "/home/jelle/Downloads/pyinstaller-1.5.1/archive.py", line 42, in <module>
    import struct
ImportError: No module named struct
Traceback (most recent call last):
  File "<string>", line 25, in <module>
ImportError: No module named archive

我正在使用 Ubuntu 12.04 和 Python 2.7.3。我的 PYTHONPATH 包括/usr/lib/python2.7。看起来问题好像是缺少模块 _struct,但我不知道在哪里可以找到它。我试过 pyinstaller 1.5.1 和开发版,这里都不起作用。

请帮忙!

python pyinstaller.py ../helloworld.py 的输出:

 7 INFO: wrote /home/jelle/Downloads/pyinstaller-2.0/helloworld/helloworld.spec
    27 INFO: UPX is not available.
    583 INFO: checking Analysis
    583 INFO: building Analysis because out00-Analysis.toc non existent
    583 INFO: running Analysis out00-Analysis.toc
    702 INFO: Analyzing /home/jelle/Downloads/pyinstaller-2.0/support/_pyi_bootstrap.py
    1570 INFO: Analyzing /home/jelle/Downloads/pyinstaller-2.0/PyInstaller/loader/archive.py
    1637 INFO: Analyzing /home/jelle/Downloads/pyinstaller-2.0/PyInstaller/loader/carchive.py
    1701 INFO: Analyzing /home/jelle/Downloads/pyinstaller-2.0/PyInstaller/loader/iu.py
    1720 INFO: Analyzing ../helloworld.py
    1721 INFO: Hidden import 'encodings' has been found otherwise
    1721 INFO: Looking for run-time hooks
    1721 INFO: Analyzing rthook /home/jelle/Downloads/pyinstaller-2.0/support/rthooks/pyi_rth_encodings.py
    2197 INFO: Looking for Python library libpython2.7.so
    objdump: section '.dynamic' mentioned in a -j option, but not found in any input file
    2308 INFO: Warnings written to /home/jelle/Downloads/pyinstaller-2.0/helloworld/build/pyi.linux2/helloworld/warnhelloworld.txt
    2311 INFO: checking PYZ
    2311 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
    2312 INFO: building PYZ out00-PYZ.toc
    2706 INFO: checking PKG
    2706 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
    2706 INFO: building PKG out00-PKG.pkg
    2711 INFO: checking EXE
    2712 INFO: rebuilding out00-EXE.toc because helloworld missing
    2712 INFO: building EXE from out00-EXE.toc
    2772 INFO: Appending archive to EXE /home/jelle/Downloads/pyinstaller-2.0/helloworld/build/pyi.linux2/helloworld/helloworld
    2773 INFO: checking COLLECT
    2773 INFO: building COLLECT out00-COLLECT.toc

顺便说一句:我的 helloworld.py 只包含语句打印“hello world”。我尝试将 #!/usr/bin/python2.7 放在顶部。

最佳答案

查看系统变量LD_LIBRARY_PATH的值

echo $LD_LIBRARY_PATH

它可能指向错误的 python 库 libpython2.7.so。

在我的例子中,我可以通过重置来解决这个问题:

export LD_LIBRARY_PATH=

关于python - pyInstaller 可执行文件在 Ubuntu 12.04 Precise 上缺少模块 "_struct",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941828/

相关文章:

python - Pyinstaller 将 opencv 从 Windows 10 分发到 Windows <10,缺少 ucrt dlls api-ms-win-crt

python - 无法从 python-ldap 连接到 Windows Server 2016 上的 ldaps

python - flask 蓝图索引URL不断添加斜杠

perl - 如何判断使用的模块是否是纯 perl?

python - 修改 Python 模块的常见做法

python - 编译程序时无法包含图标

python - 在 Python 中从父类调用方法

python - 如何使用Python远程读取和写入HDFS?

perl - 单个字符串中对象返回的 HASH 元素

Python使用配置文件创建Windows exe来传递用户名和密码