夜阑卧听风吹雨

铁马冰河入梦来

Loading

pyintaller linux 打包问题

背景

嫌啰嗦直接目录跳转下去看解决方法

本来异想天开想看 PyInstaller 能不能在 Window 编译打包 linux 可直接运行的 python 程序,不想在另一台 linux 上安装 python 环境。然后:

PyInstaller is tested against Windows, MacOS X, and Linux. However, it is not a cross-compiler; to make a Windows app you run PyInstaller on Windows, and to make a Linux app you run it on Linux, etc. x PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD but testing against them is not part of our continuous integration tests, and the development team offers no guarantee (all code for these platforms comes from external contributions) that PyInstaller will work on these platforms or that they will continue to be supported.

前面的话,直接用谷歌翻译就是:“PyInstaller 针对 Windows、MacOS X 和 Linux 进行了测试。但是,它不是交叉编译器;要制作一个 Windows 应用程序,您可以在 Windows 上运行 PyInstaller,而要制作一个 Linux 应用程序,您可以在 Linux 上运行它,等等。”

所以最终还是在一台已经安装好 python 的 linux 机器上进行打包。

pyinstaller -F dump.py打包后,报错:

OSError: Python library not found: libpython3.10.so.1.0, libpython3.10m.so.1.0, libpython3.10mu.so.1.0, libpython3.10.so, libpython3.10m.so
This means your Python installation does not come with proper shared library files.
This usually happens due to missing development package, or unsuitable build parameters of the Python installation.

  • On Debian/Ubuntu, you need to install Python development packages:
    • apt-get install python3-dev
    • apt-get install python-dev
  • If you are building Python by yourself, rebuild with --enable-shared (or, --enable-framework on macOS).

问题一:OSError: Python library not found: 解决

因为这台机器也是我很久以前编译安装的 python,根据报错的最后一句话:“If you are building Python by yourself, rebuild with --enable-shared (or, --enable-framework on macOS).”,我们直接重新配置安装一下 python 就可以了(没逃过!😑但还是可以少做几步)

在源码解压文件夹下,重新配置、安装:

# 根据自己的 python 安装目录自行修改 prefix
./configure --prefix=/usr/local/ --enable-shared

make && make install

重新安装后,因为我们以前已经安装过,所以也不用再配其他东西(安装前的必要组件安装,安装后的配环境变量软连接啥的)。

直接 python3 看一下,结果,又报错了:

[root@n94 lib]# python3
python3: error while loading shared libraries: libpython3.10.so.1.0: cannot open shared object file: No such file or directory

问题二:python3: error while loading shared libraries 解决

这里也是立马进行了搜索,解决:

vim /etc/ld.so.conf

# 添加上 python 安装目录的 /lib,比如我的安装位置,那就是 /usr/local/lib,可以再该目录下看到对应的 libpython3.10.so.1.0文件

# 使配置生效
/sbin/ldconfig -v

Centos下报错./python3: error while loading shared libraries: libpython3.10.so.1.0

重新运行,不再报错。重新 pyinstaller 打包,不再报错。

posted @ 2023-03-01 10:43  二次蓝  阅读(437)  评论(0编辑  收藏  举报