ModuleNotFoundError: No module named 'pefile'

目录

ModuleNotFoundError: No module named 'pefile'

问题:

解决:

完整错误:

​编辑


问题:

使用pyinstaller打包程序为exe格式。

打包过程发生如下错误:

ModuleNotFoundError: No module named 'pefile'

解决:

方法一:如果这个包不需要那么直接跳过算了

pyinstaller --hidden-import pefile

例如:

pyinstaller --onefile -w --hidden-import PyQt5.QtNetwork .\main.py

方法二:可能是缺少这个包

pip install pefile

 方法三:可能是缺少这个包

那就是pyinstaller的版本和python的版本不匹配的问题,可能需要基于python版本安装特定的pyinstaller。

conda install -c conda-forge pyinstaller=3.2.1

pip install pyinstaller=version_number

完整错误:

F:\test\test>pyinstaller -F test.pyw
Traceback (most recent call last):
  File "c:\users\user1\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\user1\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\user1\anaconda3\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 107, in run
    parser = generate_parser()
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 78, in generate_parser
    import PyInstaller.building.build_main
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 35, in <module>
    from PyInstaller.depend import bindepend
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\depend\bindepend.py", line 39, in <module>
    import pefile
ModuleNotFoundError: No module named 'pefile'

F:\test\test>pyinstaller -F test.pyw
Traceback (most recent call last):
  File "c:\users\user1\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\user1\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\user1\anaconda3\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 107, in run
    parser = generate_parser()
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 78, in generate_parser
    import PyInstaller.building.build_main
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 35, in <module>
    from PyInstaller.depend import bindepend
  File "c:\users\user1\anaconda3\lib\site-packages\PyInstaller\depend\bindepend.py", line 39, in <module>
    import pefile
ModuleNotFoundError: No module named 'pefile'

参考:

python - pyinstaller ModuleNotFoundError: No module named 'PyQt5.QtNetwork' - Stack Overflow

参考:python - No module named when using PyInstaller - Stack Overflow

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐