【pyinstaller打包exe失败】

文章讲述了在Linux系统中,由于Python3.6缺少依赖库导致PyInstaller打包失败的问题。通过创建Python3.7虚拟环境并正确配置依赖,解决了打包问题。同时解释了sys.argv在接收命令行参数中的作用。
摘要由CSDN通过智能技术生成

问题分析:

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).

解决方案:

  1. 在原系统中下载python3.7
    https://www.python.org/downloads/

  2. 在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

  3. 在原系统中,pip uninstall pyinstaller

  4. 在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;依此类推!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值