完美解决python3 6环境下,使用pyinstaller打包 exe时报错的情况

首先给大家推荐一下我老师大神的人工智能教学网站。教学不仅零基础,通俗易懂,而且非常风趣幽默,还时不时有内涵黄段子!点这里可以跳转到网站

初次使用python就被python强大的第三方库所吸引。也正因很多都是第三方库,存在更新不及时的情况也很多。
下载pyinstaller

为了偷懒我是直接使用:pip install pyinstaller 

然后开始打包:pyinstaller.exe -F -w D:\python\1\HelloWorld.py

结果报错:

D:\python\pyinstaller>pyinstaller.exe -F -w D:\python\1\HelloWorld.py
221 INFO: PyInstaller: 3.2.1
221 INFO: Python: 3.6.0
221 INFO: Platform: Windows-10-10.0.14393-SP0
221 INFO: wrote D:\python\pyinstaller\HelloWorld.spec
275 INFO: UPX is available.
275 INFO: Extending PYTHONPATH with paths
[‘D:\\python\\1’, ‘D:\\python\\pyinstaller’]
290 INFO: checking Analysis
292 INFO: Building Analysis because out00-Analysis.toc is non existent
293 INFO: Initializing module dependency graph…
296 INFO: Initializing module graph hooks…
298 INFO: Analyzing base_library.zip …
Traceback (most recent call last):
  File “C:\Programs\Python\Python36\Scripts\pyinstaller-script.py”, line 11, in <module>
    load_entry_point(‘PyInstaller==3.2.1’, ‘console_scripts’, ‘pyinstaller’)()
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\__main__.py”, line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\__main__.py”, line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py”, line 788, in main
    build(specfile, kw.get(‘distpath’), kw.get(‘workpath’), kw.get(‘clean_build’))
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py”, line 734, in build
    exec(text, spec_namespace)
  File “<string>”, line 16, in <module>
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py”, line 212, in __init__
    self.__postinit__()
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\datastruct.py”, line 161, in __postinit__
    self.assemble()
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py”, line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\depend\analysis.py”, line 560, in initialize_modgraph
    graph.import_hook(m)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 1509, in import_hook
    source_package, target_module_partname, level)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 1661, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\depend\analysis.py”, line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 2077, in _safe_import_module
    module_name, file_handle, pathname, metadata)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 2167, in _load_module
    self._scan_code(m, co, co_ast)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 2585, in _scan_code
    module, module_code_object, is_scanning_imports=False)
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 2831, in _scan_bytecode
    global_attr_name = get_operation_arg_name()
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 2731, in get_operation_arg_name
    return module_code_object.co_names[co_names_index]
IndexError: tuple index out of range

网上查阅无数资料后,发现原来pyinstaller不支持python3.6,官方给出的解决方案是用开发版替换(下载地址:https://github.com/pyinstaller/pyinstaller)

然后根据网友的指引,下载后直接用开发版的pyinstaller文件夹替换掉原来安装的。

开始再次运行:pyinstaller.exe -F -w D:\python\1\HelloWorld.py

结果还是报错:

D:\python\pyinstaller>pyinstaller.exe -F -w D:\python\1\HelloWorld.py
98 WARNING: Internal error: early pywin32 import was introduced
Traceback (most recent call last):
  File “C:\Programs\Python\Python36\Scripts\pyinstaller-script.py”, line 11, in <module>
    load_entry_point(‘PyInstaller==3.2.1’, ‘console_scripts’, ‘pyinstaller’)()
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\__main__.py”, line 62, in run
    import PyInstaller.building.build_main
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py”, line 32, in <module>
    from ..depend import bindepend
  File “c:\programs\python\python36\lib\site-packages\PyInstaller\depend\bindepend.py”, line 41, in <module>
    import pefile
ModuleNotFoundError: No module named ‘pefile’

查了很多资料,发现很多人都只是只言片语,不容易解决问题,最终功夫不负有心人

在开发版目录下运行:python setup.py install 重新安装,问题迎刃而解!

D:\python\pyinstaller>pyinstaller.exe -F -w D:\python\1\HelloWorld.py
0 WARNING: Internal error: early pywin32 import was introduced
147 INFO: PyInstaller: 3.3.dev0+007f78f65
147 INFO: Python: 3.6.0
147 INFO: Platform: Windows-10-10.0.14393-SP0
147 INFO: wrote D:\python\pyinstaller\HelloWorld.spec
200 INFO: UPX is available.
200 INFO: Extending PYTHONPATH with paths
[‘D:\\python\\1’, ‘D:\\python\\pyinstaller’]
200 INFO: checking Analysis
200 INFO: Building Analysis because out00-Analysis.toc is non existent
200 INFO: Initializing module dependency graph…
216 INFO: Initializing module graph hooks…
216 INFO: Analyzing base_library.zip …
4949 INFO: running Analysis out00-Analysis.toc
4986 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Programs\Python\Python36\python.exe
5065 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\python.exe
5149 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\python.exe
5218 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of C:\Programs\Python\Python36\python.exe
5303 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\python.exe
5387 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of C:\Programs\Python\Python36\python.exe
5470 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\VCRUNTIME140.dll
5550 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\VCRUNTIME140.dll
5618 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\VCRUNTIME140.dll
5687 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of C:\Programs\Python\Python36\VCRUNTIME140.dll
5779 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\VCRUNTIME140.dll
5950 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6035 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6103 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6187 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6266 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6350 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6436 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6504 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6595 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6667 WARNING: lib not found: api-ms-win-crt-process-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6736 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6830 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of C:\Programs\Python\Python36\python36.dll
6836 INFO: Caching module hooks…
6841 INFO: Analyzing D:\python\1\HelloWorld.py
6845 INFO: Loading module hooks…
6845 INFO: Loading module hook “hook-encodings.py”…
6921 INFO: Loading module hook “hook-pydoc.py”…
6936 INFO: Loading module hook “hook-xml.py”…
7268 INFO: Looking for ctypes DLLs
7268 INFO: Analyzing run-time hooks …
7288 INFO: Looking for dynamic libraries
7383 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7458 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7536 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7622 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7690 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7768 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7837 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
7923 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
8006 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
8088 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_ssl.pyd
8188 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\unicodedata.pyd
8253 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\unicodedata.pyd
8338 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\unicodedata.pyd
8430 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\pyexpat.pyd
8491 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\pyexpat.pyd
8591 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\pyexpat.pyd
8658 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\pyexpat.pyd
8738 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\pyexpat.pyd
8823 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
8907 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
8992 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9054 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9138 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9207 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9292 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9370 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9444 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_hashlib.pyd
9540 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_bz2.pyd
9607 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_bz2.pyd
9708 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_bz2.pyd
9786 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_bz2.pyd
9854 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_bz2.pyd
9938 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_lzma.pyd
10021 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_lzma.pyd
10092 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_socket.pyd
10170 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\_socket.pyd
10254 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Programs\Python\Python36\DLLs\select.pyd
10270 INFO: Looking for eggs
10270 INFO: Using Python library C:\Programs\Python\Python36\python36.dll
10270 INFO: Found binding redirects:
[]
10270 INFO: Warnings written to D:\python\pyinstaller\build\HelloWorld\warnHelloWorld.txt
10308 INFO: checking PYZ
10308 INFO: Building PYZ because out00-PYZ.toc is non existent
10323 INFO: Building PYZ (ZlibArchive) D:\python\pyinstaller\build\HelloWorld\out00-PYZ.pyz
10960 INFO: Building PYZ (ZlibArchive) D:\python\pyinstaller\build\HelloWorld\out00-PYZ.pyz completed successfully.
10972 INFO: checking PKG
10972 INFO: Building PKG because out00-PKG.toc is non existent
10973 INFO: Building PKG (CArchive) out00-PKG.pkg
11024 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\vcruntime140.dll
11286 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\python36.dll
11288 INFO: Updating resource type 24 name 2 language 1033
11308 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\python36.dll
13635 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_ssl.pyd
13635 INFO: Updating resource type 24 name 2 language 1033
13651 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_ssl.pyd
14882 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\unicodedata.pyd
14882 INFO: Updating resource type 24 name 2 language 1033
14897 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\unicodedata.pyd
15566 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\pyexpat.pyd
15566 INFO: Updating resource type 24 name 2 language 1033
15581 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\pyexpat.pyd
15868 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_hashlib.pyd
15869 INFO: Updating resource type 24 name 2 language 1033
15880 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_hashlib.pyd
16994 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_bz2.pyd
16994 INFO: Updating resource type 24 name 2 language 1033
17009 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_bz2.pyd
17184 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_lzma.pyd
17184 INFO: Updating resource type 24 name 2 language 1033
17199 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_lzma.pyd
17496 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_socket.pyd
17496 INFO: Updating resource type 24 name 2 language 1033
17512 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\_socket.pyd
17669 INFO: Updating manifest in C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\select.pyd
17669 INFO: Updating resource type 24 name 2 language 1033
17685 INFO: Executing – upx –lzma -q C:\Users\andrew\AppData\Roaming\pyinstaller\bincache01_py36_64bit\select.pyd
18037 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18053 INFO: Bootloader c:\programs\python\python36\lib\site-packages\pyinstaller-3.3.dev0+007f78f65-py3.6.egg\PyInstaller\bootloader\Windows-64bit\runw.exe
18053 INFO: checking EXE
18053 INFO: Building EXE because out00-EXE.toc is non existent
18053 INFO: Building EXE from out00-EXE.toc
18053 INFO: Appending archive to EXE D:\python\pyinstaller\dist\HelloWorld.exe
18084 INFO: Building EXE from out00-EXE.toc completed successfully.

点这里可以跳转到人工智能网站

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请发表评论。x
()
x