pythonpygamepyinstallerpy2exeauto-py-to-exe

How to convert a .py file to .exe file and run on any pc without installing the libraries used in py file?


I want to convert a ".py" file to ".exe" file and I have converted that using "auto-py-to-exe" But the file is not working on the other PC, it shows the error like this

ModuleNotFoundError: No module named 'pygame'.

I used 'pygame' in the .py project and the other PC doesn't have 'pygame' installed.

I'd like to convert ".py" file to ".exe" file and I'd like to run on any PC independent of whether it has Python or the respective libraries installed or not. Is there any way to do that?


Solution

  • Thank You @Starbuck5

    As @Starbuck5 mentioned in the comment.

    These sorts of problems happen when people mix up python installations on their own computer. What’s happened is that the python installation with pygame is not the same installation as the one with PyInstaller. So when PyInstaller runs, it can’t find a pygame to package. – Starbuck5

    I have created a new virtual environment and installed libraries needed for my project and auto-py-to-exe in that virtual env. Then by using auto-py-to-exe, I converted my python file to .exe file and now it's working properly.

    You can use any of these methods "auto-py-to-exe", "py2exe" or "pyinstaller", or any other method possible. Just the libraries should be accessible by pyinstaller or another method you use.

    The best way is to do this in a virtual environment.