pyinstaller 打包 python 脚本成 exe 的坑

来源:互联网 发布:coc龙宝宝升级数据 编辑:程序博客网 时间:2024/06/11 09:08

pyinstaller 打包python脚本成exe,只需要简单的两步:

pip install pyinstallerpyinstaller script.py

或者将动态链接库也打包到 exe 当中:

pyinstaller --console --onefile script.py

然后在当前目录下回产生两个目录和一个文件:dist、build、.spec ,exe 就在dist当中。

实际操作中,发生 IndexError: tuple index out of range异常,查询官网,原来不支持python3.6.

见 pyinstaller 官网说明:

PyInstaller is a program that freezes (packages) Python programs intostand-alone executables, under Windows, Linux, Mac OS X, FreeBSD,Solaris and AIX. Its main advantages over similar tools are thatPyInstaller works withPython 2.7 and 3.3—3.5, it builds smallerexecutables thanks to transparent compression, it is fullymulti-platform, and use the OS support to load the dynamic libraries,thus ensuring full compatibility.

用 python3.5 重新捣鼓一遍,这次成功了。

可在 exe 执行时,又失败了:

File "site-packages\urllib3\connectionpool.py", line 28, in <module>
  File "site-packages\urllib3\packages\six.py", line 92, in __get__
  File "site-packages\urllib3\packages\six.py", line 115, in _resolve
  File "site-packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'

查了下,有三种方法可以解决:

1、requests 包的版本问题,当前使用的是2.17的版本,换成旧版本问题解决(这个方法确实很扯淡):

pip install requests==2.10

2、更好的办法,在导入requests 包的文件中,显示的导入 queue 模块,尽管没有使用到该模块。

在脚本中加入:

import queue

同样问题解决 。

3、在制作的时候,带上 --hidden-import=queue 参数也可。

D:\ProgramData\python3.5\Scripts\pyinstaller.exe --hidden-import=queue D:\wrokingPro\CSDN_visit.py

阅读全文
0 0
原创粉丝点击