pyinstaller 打包遇到问题:Python library not found: libpython3.9m.so.1.0, libpython3.9m.so, libpython3.9.so

背景

  • 在linux部署执行python脚本的时候,要避免因为依赖带来的问题,同时不想暴露自己的代码程序,可以用pyinstaller将py文件打包成一个可执行的文件

操作

  • 安装pyinstaller
    pip install pyinstaller

  • 安装完成之后, 执行以下命令就会完成打包,在对应的目录下会生成一个dist目录,里面就是可执行的程序文件
    pyinstaller -F demo.py

遇到问题

`OSError: Python library not found: libpython3.9m.so.1.0, libpython3.9m.so, libpython3.9.so.1.0, libpython3.9.so, libpython3.9mu.so.1.0
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)`

在打包过程中遇到了打包不成功的问题,看报错事python缺少动态库,重点错误提示:
* If you are building Python by yourself, rebuild with --enable-shared(or,--enable-framework on macOS)
所以需要将python重新build,执行以下命令
cd /usr/local/python3.9/ ./configure --prefix=/usr/local/python3.9 --enable-shared --with-ssl make &make install
重新打包编译了python解释器,然后再执行以下, 将编译的依赖库拷贝到系统库中,
cp libpython3.so libpython3.9.so.1.0 /usr/lib64/
至此,就可以继续执行上面的打包命令了!

上一篇:直播软件开发的直播平台源码搭建中流媒体技术详解


下一篇:阻塞和非阻塞