Python 使用 pyinstaller 创建 exe 文件

时间:2021-01-12 13:52:49

标签: python windows pyinstaller

我编写了一个程序,用 face_recognition 检测和识别访客。我尝试使用 pyinstaller 制作 exe 文件。它是制作 .exe 文件,但是当我运行 .exe 时出现错误。

E:\python source\python examples\Visitors\dist>main_window.exe
Traceback (most recent call last):
  File "main_window.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "e:\python source\python-3.9.1\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    def find_spec(self, fullname, path=None, target=None):
  File "face_recognition\__init__.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "e:\python source\python-3.9.1\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    def find_spec(self, fullname, path=None, target=None):
  File "face_recognition\api.py", line 20, in <module>
RuntimeError: Unable to open C:\Users\SHAHRA~1\AppData\Local\Temp\_MEI144802\face_recognition_models\models\shape_predictor_68_face_landmarks.dat
[13080] Failed to execute script main_window

我在 github 上的源代码: “** https://github.com/shahram-arefhakimi/Visitors_with_PySide2 **”

1 个答案:

答案 0 :(得分:0)

我之前遇到过这个问题,并且有一个解决方案。当您在终端(cmd 或 PowerShell)中键入此内容时:

pyinstaller --onefile -w filename.py

如果你删除

-w

原来如此

pyinstaller --onefile filename.py

然后你就可以正常运行exe了

这将工作 99% 但如果不是,那么您的代码可能有错误