问题分析:
linux系统自带的python3.6, pyinstaller -F xxx.py打包失败, 安装python3.7,用虚拟环境pyinstaller -F xxx.py打包成功。应该是自带的python3.6 缺少dependence库。
问题描述:
pyinstaller -F xxx.py打包失败
`提示:
raise IOError(msg)
OSError: Python library not found: libpython3.6.so, libpython3.6m.so, libpython3.6.so.1.0, libpython3.6mu.so.1.0, libpython3.6m.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).
解决方案:
-
在原系统中下载python3.7
https://www.python.org/downloads/ -
在linux系统里创建一个虚拟环境
pip install virtualenv
install virtualenvwrapper
将如下2条语句添加到~/.bashrc里(vi ~/.bashrc, source ~/.bashrc)
export WORKON_HOME=/home/path001/.virtualenvs
source /home/path002/virtualenvwrapper.sh
virtualenvwrapper.sh路径可以通过find -name virtualenvwrapper.sh找到
mkvirtualenv -p python3.7 env003 -
在原系统中,pip uninstall pyinstaller
-
在env003中,pip install pyinstaller
在env003中就可以用pyinstaller -F xxx.py了
others:
进入env003: source /home/path001/.virtualenvs/test3/bin/activate
退出env003: deactivate
在linux系统下打包的文件只能在linux系统运行,想在windows下运行,就需要在windows下打包。
sys.argv[0], sys.argv[1], sys.argv[2]…什么意思?
从程序外部获取参数的方式,例如,当使用命令行运行Python程序时,操作系统会传递一系列参数给程序,这些参数被存储在“sys.argv”中,列表中通常包含程序本身的名称,之后是传递给程序的各个参数。
例如:上面pyinstaller 打包出来的exe文件为test003.exe, dos窗口运行test003.exe, 则sys.argv[0]表示test003.exe;如果dos窗口运行test003.exe …/file003.csv, 则sys.argv[0]表示test003.exe,sys.argv[1]表示…/file003.csv;依此类推!