gpt4 book ai didi

python - Linux 下的 PyInstaller 和 NumPy

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:27:19 24 4
gpt4 key购买 nike

我正在尝试将我的 Python 程序转换为适用于 Windows 和 Linux 的独立可执行文件。看来 PyInstaller 是完成此任务的一个很好的解决方案。它在 Windows 下很容易转换,但是我不能让它在 Linux 上工作(在两台不同的 Ubuntu 机器上测试它)。原始的 Python 程序可以简化为简单的两行代码:

from numpy import log
print '%8.6f' % log(5)

像这样调用时工作正常:

anton@op:~/bin$ python test_numpy.py
1.609438

在 PyInstaller 中编译后,出现错误:

anton@op:~/bin/dist/test_numpy$ ./test_numpy
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy", line 153, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.add_newdocs", line 13, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib", line 8, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib.type_check", line 11, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.core", line 6, in <module>
ImportError: cannot import name multiarray

所以问题与 numpy 库没有正确导入有关。

我已经尝试按照 pyinstaller 的建议添加隐藏的 Hook ,但没有任何帮助,而且我总是收到此错误。有什么想法吗?

最佳答案

我终于能够解决这个问题。

这是我在 hithub 上找到的:

The executable that PyInstaller builds is not fully static, in that it still depends on the system libc. Under Linux, the ABI of GLIBC is backward compatible, but not forward compatible. So if you link against a newer GLIBC, you can't run the resulting executable on an older system. The supplied binary bootloader should work with older GLIBC. However, the libpython.so and other dynamic libraries still depends on the newer GLIBC. The solution is to compile the Python interpreter with its modules (and also probably bootloader) on the oldest system you have around, so that it gets linked with the oldest version of GLIBC.

所以看起来当前稳定的 PyInstaller 版本可能已经过时了。由于降级所有软件包不切实际,我将 PyInstaller 升级到最新的开发版本 (3.0.dev2),瞧瞧!现在一切正常,所有依赖项都已正确处理,无需任何自定义 Hook 。

希望能对某人有所帮助。

关于python - Linux 下的 PyInstaller 和 NumPy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788942/

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