Pyinstaller打包32位exe

使用 pyinstaller 打包 32 位软件,结果总是一闪而过,而之前同样的程序打包了 64 位exe,一点问题都没有。

(直接在cmd中运行exe)错误信息如下:

1
2
3
4
5
6
7
8
(py32) D:\PythonWorkspace\report_forms>.\dist\main.exe
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import pymssql
  File "src\pymssql.pyx", line 1, in init pymssql
  File "src\_mssql.pyx", line 57, in init _mssql
ModuleNotFoundError: No module named 'decimal'
[5136] Failed to execute script main

可以看到报错的是没有找到 decimal模块,也是参考网上解决办法

Just as a suggestion, put an import decimal at the top of your program. It looks ike _mssql might be doing dynamic imports in __load method which will “confuse” py2exe because it can’t know about dynamic imports which happen at runtime.
打包程序无法判断动态调用,_mssql是动态调用的,就是用才调用,不会一开始就调用。

打包错误

1
2
3
4
5
import _mssql
import decimal

_mssql.__version__
decimal.__version__

32位上系统运行报错

1
2
VCRUNTIME140.dll could not be extracted!
fopen: Permission denied

安装vc2015之后照样有问题,StackOverflow解决方式:更换pyinstaller版本,由4.0更换到3.6版本

无法定位程序输入点

这是更换pyinstaller版本之后,继续出现的问题。双击文件报错:无法定位程序输入点GetFinalPathNameByHandleW于动态链库KERNEL32.dll上,cmd中运行报错:Error loading Python dll,查到解决方法是说 python3.5 以后就不支持xp系统了,尝试更换 3.4 版本的python。

conda 无法配置py3.4

镜像文件没有3.4的python,更改镜像源即可

1
2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

Pil 和 image模块错误

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Traceback (most recent call last):
  File "site-packages\qrcode\image\pil.py", line 6, in <module>
ImportError: No module named 'PIL'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 58, in <module>
  File "site-packages\qrcode\main.py", line 289, in make_image
  File "d:\anaconda3\envs\py34b32\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 627, in exec_module
  File "site-packages\qrcode\image\pil.py", line 8, in <module>
ImportError: No module named 'Image'
[3544] Failed to execute script main

不需要太复杂的二维码,更换二维码生成模块为PyQrcode,而不用之前的qrcode

在win server 2003 R2 上运行的最终版本

python: 3.4.5
pyinstaller: 3.5
pymssql: 2.1.3 (2.1.4以上就不支持py33了)
pypng: 0.0.20
PyQRCode: 1.2.1