问题描述
当前在通过pyinstaller打包exe时遇到问题。
我在pycharm下创建了一个虚拟环境,我的程序非常简单
a = input("please input a :")
b = input("please input b: ")
c = print(a+b)
存储在test.py中的代码。然后在pycharm consle上输入pyinstaller -F test.py
,如下所示。如您所见,找不到许多库,并且打包失败。
(venv) C:\cheng\Project\STC_Tool\venv>pyinstaller -v
3.6
(venv) C:\cheng\Project\STC_Tool\venv>pyinstaller -F test.py
67 INFO: PyInstaller: 3.6
67 INFO: Python: 3.7.8
70 INFO: Platform: Windows-10-10.0.18362-SP0
72 INFO: wrote C:\cheng\Project\STC_Tool\venv\test.spec
73 INFO: UPX is not available.
74 INFO: Extending PYTHONPATH with paths
['C:\\cheng\\Project\\STC_Tool\\venv','C:\\cheng\\Project\\STC_Tool\\venv']
75 INFO: checking Analysis
77 INFO: Building because C:\cheng\Project\STC_Tool\venv\test.py changed
78 INFO: Initializing module dependency graph...
80 INFO: Caching module graph hooks...
83 INFO: Analyzing base_library.zip ...
2178 INFO: Processing pre-find module path hook distutils
2191 INFO: distutils: retargeting to non-venv dir 'C:\\cheng\\Software\\Python\\lib'
3247 INFO: Caching module dependency graph...
3348 INFO: running Analysis Analysis-00.toc
3351 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\cheng\project\stc_tool\venv\scripts\python.exe
3365 WARNING: lib not found: VERSION.dll dependency of c:\cheng\project\stc_tool\venv\scripts\python.exe
3371 INFO: Analyzing C:\cheng\Project\STC_Tool\venv\test.py
3373 INFO: Processing module hooks...
3374 INFO: Loading module hook "hook-distutils.py"...
3375 INFO: Loading module hook "hook-encodings.py"...
3656 INFO: Loading module hook "hook-pydoc.py"...
3657 INFO: Loading module hook "hook-sysconfig.py"...
3659 INFO: Loading module hook "hook-xml.py"...
3910 INFO: Looking for ctypes DLLs
3915 INFO: Analyzing run-time hooks ...
3917 INFO: Looking for dynamic libraries
3937 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\select.pyd
3947 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\select.pyd
3966 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\_socket.pyd
3974 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\_socket.pyd
3978 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\_lzma.pyd
3994 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\_lzma.pyd
4001 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\_bz2.pyd
4027 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\_bz2.pyd
4052 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\_hashlib.pyd
4062 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\_hashlib.pyd
4071 WARNING: lib not found: libcrypto-1_1.dll dependency of C:\cheng\Software\Python\DLLs\_hashlib.pyd
4079 WARNING: lib not found: libssl-1_1.dll dependency of C:\cheng\Software\Python\DLLs\_ssl.pyd
4095 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\_ssl.pyd
4097 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\_ssl.pyd
4106 WARNING: lib not found: libcrypto-1_1.dll dependency of C:\cheng\Software\Python\DLLs\_ssl.pyd
4128 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\unicodedata.pyd
4141 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\unicodedata.pyd
4161 WARNING: lib not found: VCRUNTIME140.dll dependency of C:\cheng\Software\Python\DLLs\pyexpat.pyd
4171 WARNING: lib not found: python37.dll dependency of C:\cheng\Software\Python\DLLs\pyexpat.pyd
4174 INFO: Looking for eggs
4174 INFO: Python library not in binary dependencies. Doing additional searching...
4180 INFO: Using Python library
4180 INFO: Found binding redirects:
[]
4194 INFO: Warnings written to C:\cheng\Project\STC_Tool\venv\build\test\warn-test.txt
4252 INFO: Graph cross-reference written to C:\cheng\Project\STC_Tool\venv\build\test\xref-test.html
4261 INFO: checking PYZ
4268 INFO: Building because toc changed
4270 INFO: Building PYZ (ZlibArchive) C:\cheng\Project\STC_Tool\venv\build\test\PYZ-00.pyz
4875 INFO: Building PYZ (ZlibArchive) C:\cheng\Project\STC_Tool\venv\build\test\PYZ-00.pyz completed successfully.
4890 INFO: checking PKG
4891 INFO: Building because toc changed
4893 INFO: Building PKG (CArchive) PKG-00.pkg
Traceback (most recent call last):
File "C:\cheng\Software\Python\lib\runpy.py",line 193,in _run_module_as_main
"__main__",mod_spec)
File "C:\cheng\Software\Python\lib\runpy.py",line 85,in _run_code
exec(code,run_globals)
File "C:\cheng\Project\STC_Tool\venv\Scripts\pyinstaller.exe\__main__.py",line 7,in <module>
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\__main__.py",line 114,in run
run_build(pyi_config,spec_file,**vars(args))
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\__main__.py",line 65,in run_build
PyInstaller.building.build_main.main(pyi_config,**kwargs)
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\build_main.py",line 734,in main
build(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\build_main.py",line 681,in build
exec(code,spec_namespace)
File "C:\cheng\Project\STC_Tool\venv\test.spec",line 33,in <module>
console=True )
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\api.py",line 436,in __init__
upx_exclude=self.upx_exclude
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\api.py",line 199,in __init__
self.__postinit__()
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\datastruct.py",line 160,in __postinit__
self.assemble()
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\api.py",line 262,in assemble
dist_nm=inm)
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\utils.py",line 220,in checkCache
digest = cacheDigest(fnm,redirects)
File "c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\building\utils.py",line 365,in cacheDigest
with open(fnm,"rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: ''
如果我删除了-F
选项并直接输入pyinstaller test.py
,则打包将成功
(venv) C:\cheng\Project\STC_Tool\venv>pyinstaller test.py
65 INFO: PyInstaller: 3.6
65 INFO: Python: 3.7.8
66 INFO: Platform: Windows-10-10.0.18362-SP0
68 INFO: wrote C:\cheng\Project\STC_Tool\venv\test.spec
70 INFO: UPX is not available.
70 INFO: Extending PYTHONPATH with paths
['C:\\cheng\\Project\\STC_Tool\\venv','C:\\cheng\\Project\\STC_Tool\\venv']
70 INFO: checking Analysis
75 INFO: checking PYZ
98 INFO: checking PKG
98 INFO: Building because toc changed
99 INFO: Building PKG (CArchive) PKG-00.pkg
125 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
128 INFO: Bootloader c:\cheng\project\stc_tool\venv\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
129 INFO: checking EXE
131 INFO: Building because toc changed
132 INFO: Building EXE from EXE-00.toc
134 INFO: Appending archive to EXE C:\cheng\Project\STC_Tool\venv\build\test\test.exe
137 INFO: Building EXE from EXE-00.toc completed successfully.
142 INFO: checking COLLECT
WARNING: The output directory "C:\cheng\Project\STC_Tool\venv\dist\test" and ALL ITS CONTENTS will be REMOVED! Continue? (y/N)y
On your own risk,you can use the option `--noconfirm` to get rid of this question.
2769 INFO: Removing dir C:\cheng\Project\STC_Tool\venv\dist\test
2780 INFO: Building COLLECT COLLECT-00.toc
2830 INFO: Building COLLECT COLLECT-00.toc completed successfully.
但是单击后,test.exe闪烁并关闭,我使用屏幕录制工具捕获了Flash错误
,它显示Error loading Python DLL 'c:\cheng\Project\STC_Tool\venv\dist\test'
win10上安装的python是python3.7,我正在使用win10 64位操作系统。
能给我一些建议吗?
解决方法
卸载pyinstaller之后,再次重新安装pyinstaller,问题已解决。
请考虑也更新系统变量。