Record a problem with pyinstaller packaging

The problem that pyinstaller packaging cannot run

Question in detail

When I use pythonInstaller to package python files, I have a problem that it cannot be run. The
first package: execute code
without black window program

pyinstaller -F mainwindow.py

After the build is packaged:
insert image description here
it cannot be run, to be precise, it flashes back...
Adjust the packaging parameters - no black window program:

Pyinstaller -F -w mainwindow.py

insert image description here
After executing the exe file it appears:
insert image description here

Position to the last sentence:

Traceback (most recent call last):
  File "mainwindow.py", line 13, in <module>
    from out_window import Ui_OutputDialog
  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 "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "out_window.py", line 11, in <module>
    import face_recognition
  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 "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  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 "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "face_recognition\api.py", line 20, in <module>
RuntimeError: Unable to open C:\Users\12294\Desktop\mainwindow\face_recognition_models\models\shape_predictor_68_face_landmarks.dat

The program failed to open an associated library file - the file under face_recognition_models

solve

Let me explain here that the environment of the project is completed in anaconda, that is to say, our packaged program is missing the face_recognition_models library.
Then go to the environment of anaconda and take a look:
insert image description here
copy the entire folder to the root directory we packaged Can

Tips small problem (missing mainwindow.ui)

This problem is also encountered in the subsequent execution of the exe file:
Take my project as an example, the project structure is as follows:
insert image description here
Here, after executing pyinstaller, it is observed that in addition to the .py file in the project being packaged, other files (qt.ui file) , image files and other associated files) are not packaged

solve

Move the missing files into the packaged folder
and finally execute it, it works perfectly

Guess you like

Origin blog.csdn.net/weixin_50679163/article/details/124307402