各类环境各类坑,一步一搜索,终于解决了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刷新