各類環境各類坑,一步一搜索,終於解決了CentOS下使用的問題,記錄一下html
安裝,參考http://www.javashuo.com/article/p-gwcviany-eo.htmlpython
windows10, 很容易,直接pip搞定linux
pip install pywin32 pip install PyInstaller
試一下。flask
建立一個python文件ubuntu
from flask import Flask from flask import request app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def home(): return 'test' if __name__ == '__main__': app.run()
打開cmd,轉到文件路徑windows
pyinstaller -F app.py
雖然用了flask和numpy,可是並無出錯,不須要像文章中說的那樣複製package目錄到文件夾,直接就打包好了。bash
dist目錄下生成了app.exe,竟然有212MB。打開,沒問題。複製到同事電腦,沒有python環境也能夠執行。很好。服務器
服務器是linux,先到虛擬機的CentOS上試一下吧app
安裝仍是很簡單ui
pip install pyinstaller
執行如下試試,報錯:pyinstaller: command not found
安裝沒問題啊
查到這篇文章https://blog.csdn.net/qq_35614920/article/details/77404323
要不試試源文件安裝,官網地址
解壓縮
tar -xzv PyInstaller-3.4.tar.gz
解壓完成後進入文件夾執行
python setup.py install
再打包試一下,仍是報錯:pyinstaller: command not found
繼續搜:https://superuser.com/questions/1310800/pyinstaller-command-not-found
這是由於pyinstaller沒有被放到/usr/bin目錄下,須要從python目錄下複製過去
cp /usr/local/python36/bin/pyinstaller /usr/bin/pyinstaller
再來,竟然有新的錯誤:
OSError: Python library not found: libpython3.6m.so.1.0, libpython3.6mu.so.1.0, libpython3.6.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)
這個兄弟看起來嘗試了很多方案 pyinstaller編譯python腳本爲單文件可執行文件遇到的問題
安裝python3-dev,python-dev。這是對ubuntu系統的,CentOS不須要
文章裏提到stackoverflow的一個方案
1st. check your system if it has libpython3.4m.so.1.0. If yes, go to step 2nd. If no, download it(I'm using anaconda python, so I have it in anaconda folder.)
2nd. sudo cp /folder/to/your/libpython3.4m.so.1.0 /usr/lib
照着樣子找一下,竟然找不到
find / -name libpython3.6mu.so.1.0
繼續找爲何系統沒有這個文件。https://www.cnblogs.com/Tommy-Yu/p/6144512.html
python是本身裝的,在安裝以前指定設置的時候,須要指定--enable-shared參數
When running configure, you should be supplying the --enable-shared option to ensure that shared libraries are built for Python. By not doing this you are preventing any application which wants to use Python as an embedded environment from working.
好吧,從新編譯python,順便打開ssl,避免之後掉坑
./configure --prefix=/usr/local/python36 --enable-shared --with-ssl make make install
回頭仔細看看以前的報錯信息,裏面已經說過了:
If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)
python從新裝好了,再試一下打包
pyinstaller -F app.py
竟然仍是報找不到so,http://www.cnblogs.com/trasin/p/6212124.html
查看動態庫狀況
ldd /usr/local/python36/bin/python3
把須要的.so複製到lib目錄
cp libpython3.6m.so.1.0 /usr/lib64/
再次打包,這下能夠了。這種環境問題真是夠煩的
pyinstaller -F app.py
pyinstaller打包報錯for real_module_name, six_moduleAttributeError: 'str' object has no attribute 'items'
https://stackoverflow.com/questions/35613300/pyinstaller-compile-to-exe
更新setuptools
pip install -U --pre setuptools
其餘文章說的一些解決辦法,固然,對個人問題沒有效果
http://www.pianshen.com/article/423794883/
在/etc/ld.so.conf中添加
/usr/local/lib64
/usr/local/lib
而後ldconfig刷新