0

I'm trying to create a python executable, using the command

pyinstaller --onefile src/motiondemo.py

It succeeds, but when running the executable, I get the following exception:

(env) PS C:\code\exprojects\motiondemo\dist> .\motiondemo.exe
pygame 2.0.2 (SDL 2.0.16, Python 3.9.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "motiondemo.py", line 7, in <module>
  File "C:\Users\MSHIRAZ\AppData\Local\Temp\embedded.zhlo3qfk.zip\shibokensupport\__feature__.py", line 142, in _import
  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 546, in exec_module
  File "video_widgets.py", line 4, in <module>
  File "C:\Users\MSHIRAZ\AppData\Local\Temp\embedded.zhlo3qfk.zip\shibokensupport\__feature__.py", line 142, in _import
  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 546, in exec_module
  File "core.py", line 5, in <module>
  File "C:\Users\MSHIRAZ\AppData\Local\Temp\embedded.zhlo3qfk.zip\shibokensupport\__feature__.py", line 142, in _import
  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 546, in exec_module
  File "tracker.py", line 3, in <module>
  File "C:\Users\MSHIRAZ\AppData\Local\Temp\embedded.zhlo3qfk.zip\shibokensupport\__feature__.py", line 142, in _import
  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 546, in exec_module
  File "particle.py", line 32, in <module>
  File "particle.py", line 34, in Particle
FileNotFoundError: No such file or directory.
[820] Failed to execute script 'motiondemo' due to unhandled exception!
Asif Shiraz
  • 864
  • 1
  • 12
  • 27
  • I can only guess that there is some code on line 34 of your `particle.py` script that is attempting to load a file that isn't there. – Luke Woodward Oct 12 '21 at 21:19
  • It looks like you neglected to name in your `.spec` file the file that `particle.py` is trying to load. – BoarGules Oct 12 '21 at 21:34
  • Line 34 in particle.py is this: FIRE = pygame.image.load(os.path.join('images', 'fire.png')) – Asif Shiraz Oct 13 '21 at 22:03
  • So the file is there. Maybe paths are messing up between the windows executable and the original python – Asif Shiraz Oct 13 '21 at 22:03
  • It's not that the paths are messing up. When you bundle the application, Pyinstaller takes any assets you need (such as images) and bundles them also. This is so you can then distribute the bundle to someone and expect it to work properly. However, when the run the .exe the 'root' path is different to when you run it as a script. So using a path relative to your .py script won't work. There are a few answers that address this on SO like [this](https://stackoverflow.com/questions/42251295/file-path-for-pyinstaller-bundled-images) – wstk Oct 14 '21 at 13:56

0 Answers0