no module named 'pygame'

33 views
Skip to first unread message

Novice Philadelphia .D

unread,
Aug 22, 2019, 12:25:33 PM8/22/19
to PyInstaller
I am trying to use Pyinstaller to make my .py to .exe.
I used >> pyinstaller --onefile -w main.py  to generate files and an exe.
But when I tried to run it by terminal in PyCharm, these error comes out:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import Setting
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "Setting.py", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'
[5458] Failed to execute script main

I have added 'pygame' inside hiddenimports and the absolute path of pygame folder(something like '....../venv/lib/python3.7/site-packages/pygame/') inside pathex in my main.spec.
These are the solutions that I can find from google but it doesn't work. Same error just comes out again :(

I've tried import Pygame in just Hello World but still having error.

Any can help me?

Shil Nevado

unread,
Aug 27, 2019, 3:03:20 AM8/27/19
to PyInstaller
Try to make an egg with pygame and add it to the data. Also add into hiddenimports as you are doing and install it in pip. I think you can't do the onefile tag (not sure 100%) as you need folders in order to search for the aditional script files.

I'm doing all of them and my program is working. I don't know if all is needed but with those, it is working.
Reply all
Reply to author
Forward
0 new messages