我想将我的python文件设为exe文件,但是我收到了错误。
我点击了cmd屏幕中的pyinstaller -w file.py
,
然后我收到了如下错误。
Traceback (most recent call last):
File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "C:\Python36\lib\site-packages\PyInstaller\__main__.py", line 92, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Python36\lib\site-packages\PyInstaller\__main__.py", line 46, in run_
build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Python36\lib\site-packages\PyInstaller\building\build_main.py", line
791, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
File "C:\Python36\lib\site-packages\PyInstaller\building\build_main.py", line
737, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "C:\Python36\lib\site-packages\PyInstaller\building\build_main.py", line
213, in __init__
self.__postinit__()
File "C:\Python36\lib\site-packages\PyInstaller\building\datastruct.py", line
161, in __postinit__
self.assemble()
File "C:\Python36\lib\site-packages\PyInstaller\building\build_main.py", line
472, in assemble
module_hook.post_graph()
File "C:\Python36\lib\site-packages\PyInstaller\building\imphook.py", line 410
, in post_graph
self._load_hook_module()
File "C:\Python36\lib\site-packages\PyInstaller\building\imphook.py", line 377
, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "C:\Python36\lib\site-packages\PyInstaller\compat.py", line 728, in impor
tlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrappe
r
File "<frozen importlib._bootstrap_external>", line 823, in load_module
File "<frozen importlib._bootstrap_external>", line 682, in load_module
File "<frozen importlib._bootstrap>", line 251, in _load_module_shim
File "<frozen importlib._bootstrap>", line 675, in _load
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Python36\lib\site-packages\PyInstaller\hooks\hook-pytest.py", line 16
, in <module>
hiddenimports = pytest.freeze_includes()
AttributeError: module 'pytest' has no attribute 'freeze_includes'
我在我的python文件中添加了import pytest
,但没有任何变化。
请让我知道错误。
答案 0 :(得分:3)
此问题是由pytest的过期版本引起的。我能够一个接一个地使用pip uninstall pytest
和pip install pytest
来解决它,以更新到最新版本的pytest。
答案 1 :(得分:0)
在我的情况下,Jacob建议的更新并没有真正帮助,因为违反了其他要求。我的程序中不需要pytest,所以我只是从PyInstaller中删除了pytest钩子。我的路是
C:\Python37-32\Lib\site-packages\PyInstaller\hooks\hook-pytest.py
所以并不是真正的“解决方案”,但仍然对我有用。