pyinstaller 打包遇到問題: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


背景

  • 在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/
至此,就可以繼續執行上面的打包命令了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM