python打包exe

在编写了python工具之后,为了方便在windows下使用,会将文件打包成exe。下面介绍打包的一些知识。

安装环境

# 安装打包库
pip install pyinstaller
# 更新打包库
pip install --upgrade pyinstaller
  • 尝试过在3.6版本下,使用了这两个指令,打包的文件还是会出现这样的问题:
config> .\export_excel.exe
Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 13, in <module>
  File "c:\users\abel\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pkg_resources\__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'

原因还是来自于下载的版本太陈旧造成。3.6版本的python下运行需要安装最新的版本。

pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz

你也可以从GitHub里面下载最新的版本。

https://github.com/pyinstaller/pyinstaller/tarball/develop

这段文字是官方网站的原文:

The latest stable release of PyInstaller is 3.6 (Change Log).

Release 3.6: stable, supports Python 2.7, 3.5–3.7

PyInstaller 3.6 (tar.gz) (pgp, sha-256: 3730fa80d088f8bb7084d32480eb87cbb4ddb64123363763cf8f2a1378c1c4b7)

Development: unstable, supports Python 3.5–3.7

Current development code (tar.gz)

Current development code (zip)

If you want to motify the source, you may better clone the git repository using git clone https://github.com/pyinstaller/pyinstaller and may want to refer to the Development Guide in the manual.

Older (obsolete) releases can be found at the full list of releases.

打包流程

基本指令:

pyinstaller [options] script [script …] | specfile

现在我编写的工具是console,所以需要使用这个选项

Windows and Mac OS X specific options

-c, --console, --nowindowed
    Open a console window for standard i/o (default). On Windows this option will have no effect if the first script is a ‘.pyw’ file.

更加详细的信息,可以查阅,引用部分,使用手册

引用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值