0

I want to transform a Python script to an .exe to share it with friends. I've tried with auto-py-to-exe, but here is what I get when I open it:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
ModuleNotFoundError: No module named 'pygame'

I saw somewhere that I had to indicate in auto-py-to-exe's interface the module name here:

Hidden Importation PyGame

But I still get the same error.

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
Khalid Ab
  • 195
  • 1
  • 3
  • 17

2 Answers2

2

I have experienced this before where I export .py into .exe with --onedir setup. Here are the solutions that I might suggest (and works for me)

1. Export as --onefile

auto-py-to-exe screenshot

Exporting using --onefile creates only a single .exe file instead of having a folder contain hundreds of other supporting files (is that term exist? IDK). but the drawback is the file will be painstakingly slow to load up.

but if you export it as --onefile but still doesn't work,

2. Ensure the pygame is in the same directory as your .exe file

Apparently your .exe app is looking for the pygame module but failed. Try putting it in the same directory as your source code

1

There are multiple ways to convert a python file(.py) to an executable(.exe) -:

Also, as mentioned in the comments by @Nanthakumar JJ and by @Amar Haiqal in his answer, make sure the --onefile option is checked while using auto-py-to-exe for conversion. Further, pygame module has to be present within the directory of the main file that is being compiled, as it will look for pygame and raise a ModuleNotFoundError, if the module is not found, being an .exe it will not look for the module on PYTHONPATH.

--onefile option in auto-py-to-exe

typedecker
  • 1,351
  • 2
  • 13
  • 25