windows版本
1、需要安裝pyinstaller,通過以下命令:
通過pip install pyinstaller
其中pyinstaller對python3.6不兼容問題,但是在打包時會出現問題。解決辦法是升級python爲3.7版本,python3.7支持pyinstaller
2、安裝好了pyinstaller後,通過命令pyinstaller -F xx1.py xx2.py。生成和第一個py文件相同名的exe文件,其中如果出現依賴的py文件,需要添加py文件到到第一個文件之後。
Linux版本
1、同樣,通過如下命令安裝pyinstaller
pip install pyinstaller
2、在通過pyinstaller -F xx.py編譯程序的時候,出現如下錯誤:
OSError: Python library not found: libpython3.7.so.1.0, libpython3.7m.so.1.0, libpython3.7mu.so.1.0
This would mean your Python installation doesn't come with proper library files.
This usually happens by missing development package, or unsuitable build parameters of Python installation.
* On Debian/Ubuntu, you would need to install Python development packages
* apt-get install python3-dev
* apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)
提示的解決錯誤的方法是安裝python3-dev(這是在Debian/Ubuntu),而Centos下是通過yum install python3-devel安裝。其實最終解決該問題可以通過如下命令:
sudo cp /....../libpython3.7.so.1.0 /usr/lib