python - PyInstaller 在制作二进制文件时找不到 libpython2.7.so?

标签 python python-2.7 python-module pyinstaller

我正在尝试在 Linux 上使用 PyInstaller 2.0 制作 Python 脚本的二进制版本。当我运行时:

$ python pyinstaller.py myscript.py

我得到错误:

8907 INFO: Looking for Python library libpython2.7.so
Traceback (most recent call last):
...
  File "pyinstaller.py", line 91, in <module>
    raise IOError("Python library not found!")
IOError: Python library not found!

如何解决这个问题?

我正在使用:

Linux #98-Ubuntu x86_64 GNU/Linux

使用 python 2.7。系统上还有其他 Python,但我已将其设置为:

alias python="python2.7"

在我使用的服务器中,只有 /usr/lib/python2.6 而不是 /usr/lib/python2.7 但常规使用 python 2.7由我编写并且具有功能性等,所以我不明白为什么找到它的库会是个问题。有一个/usr/local/lib/libpython2.7.a

最佳答案

In the server I am using, there's only /usr/lib/python2.6 and not /usr/lib/python2.7 but python 2.7 is used routinely by me and is functional, etc. so I don't see it why it would be a problem to find its libraries. There is a /usr/local/lib/libpython2.7.a.

如果没有libpython2.7.so,当然找不到那个库了。

您能够使用 Python 解释器的原因可能是它是静态链接的。

有两种方法可以解决这个问题。

首先,您可以只为您的 Python 2.7 安装共享库。如果您使用的是旧版本的 Ubuntu,例如 Python 2.6,并且您从 python2.7 包安装了 2.7,这应该只是安装 libpython2 的问题。 7

如果您的 2.7 是从其他来源获得的,那么 Ubuntu libpython2.7 包显然将无法工作——或者它可以通过安装 python2 的第二个副本来工作。 7,可能会覆盖你已有的一些文件,这肯定会让你感到困惑。无论哪种方式,都不要这样做。要么为现有的 2.7 获取 Python 的其余部分,要么卸载 2.7 并使用 Ubuntu 软件包。 (对于某些 Python 发行版,“获取其余部分”是不可能的,因为如果您安装共享库,您将获得动态链接的 Python 可执行文件而不是静态链接的。在这种情况下,您几乎必须卸载并重新安装。)

其次,您可以使用 PyInstaller 的静态库支持。参见 ticket 420有关详细信息,但简单的想法是,如果启用此功能,并且 PyInstaller 认为您的平台应该有一个 libpython2.7.so 但找不到它,它将寻找一个 libpython2.7.a 并静态链接它。上次我需要这个时,它没有被 checkin 后备箱。快速浏览一下票证,看起来补丁现在包含在内,但在默认的 PyInstaller 构建中被禁用,并且里程碑设置为 3.0,因此,您可能仍然需要手动构建 PyInstaller 让它工作。

最后一件事:您可能确实有 libpython2.7.so,但它只是安装在奇怪的地方,例如 /opt/python27/lib 或其他东西,与/opt/python27 在你的路径上无处可去,但 /usr/local/bin/python27 可以找到它,因为它明确构建为从 /opt/中获取内容python27。这种事情往往只对使用 MacPorts 或 Fink 的 Mac 用户来说是个问题,而不是 Linux 用户,但这并非不可能。如果您认为这可能是问题所在,您可以查看 /usr/local/bin/python27 的 dl 表。

关于python - PyInstaller 在制作二进制文件时找不到 libpython2.7.so?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677359/

相关文章:

python - 使用Makefile安装pythonrequirements.txt仅更改requirements.txt

python - 为什么我的程序要求我输入 self 的值?

Python 模块 : how to prevent importing modules called by the new module

python - 为什么python2用编码转义字符保存文本?

python - 从 Anaconda Launcher 更新时出现错误消息

Python导入模块只能在新的终端窗口中工作

python - 如何覆盖模块名称(__name__)?

python - Odoo 字段访问权限/规则

python - 通过连接多个文件创建的文本文件的交互式 3D 散点图

python - 如何访问模块对象上的 dir() Python 属性?