pyinstaller打包错误:ModuleNotFoundError: No module named ‘decimal‘

pyinstaller可以将程序打包成exe文件在windows上执行,如:

pyinstaller -F main.py

可以将文件生成成一个main.exe的文件,但是在打包完成运行的时候发生了这样的报错:

D:\pyworkspace\bus4mssql\dist>D:\pyworkspace\bus4mssql\dist\main.exe
Traceback (most recent call last):
  File "main.py", line 9, in <module>
  File "d:\python3.6.8\lib\site-packages\PyInstaller\loader\pyimod03_importers.p
y", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "common\mssql\mssqlConn.py", line 8, in <module>
  File "pymssql.pyx", line 1, in init pymssql
  File "_mssql.pyx", line 52, in init _mssql
ModuleNotFoundError: No module named 'decimal'
[2168] Failed to execute script main

这是由于decimal这个隐藏的引用未声明,隐藏参数少的话,在打包的时候加入对应参数即可:

pyinstaller --hidden-import=decimal  -F main.py

执行结果:

8268 INFO: Warnings written to D:\pyworkspace\bus4mssql\build\main\warn-main.txt

8364 INFO: Graph cross-reference written to D:\pyworkspace\bus4mssql\build\main\
xref-main.html
8379 INFO: checking PYZ
8382 INFO: Building because toc changed
8382 INFO: Building PYZ (ZlibArchive) D:\pyworkspace\bus4mssql\build\main\PYZ-00
.pyz
9506 INFO: Building PYZ (ZlibArchive) D:\pyworkspace\bus4mssql\build\main\PYZ-00
.pyz completed successfully.
9522 INFO: checking PKG
9523 INFO: Building because toc changed
9523 INFO: Building PKG (CArchive) PKG-00.pkg
12193 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
12197 INFO: Bootloader d:\python3.6.8\lib\site-packages\PyInstaller\bootloader\W
indows-32bit\run.exe
12198 INFO: checking EXE
12200 INFO: Building because toc changed
12200 INFO: Building EXE from EXE-00.toc
12204 INFO: Updating manifest in D:\pyworkspace\bus4mssql\build\main\run.exe.0au
i5z1z
12204 INFO: Updating resource type 24 name 1 language 0
12206 INFO: Appending archive to EXE D:\pyworkspace\bus4mssql\dist\main.exe
12215 INFO: Building EXE from EXE-00.toc completed successfully.

你可能感兴趣的:(error,python,exe)