0

I made a program in python which I now wanted to turn into an .exe so that other people at my office, who do not have python or any python skills can use it too. This is not the first time I did this, and I am still working on the same machine, however this time I run into the "module not found" error when trying to execute the exe.

Basically I created a GUI with PySimpleGUI and then followed my own guide from last time, where I created a spec file with pyi-makespec, specifying the paths in which the packages are located. These are two locations: in C:// where python is installed, and in the "venv" folder of my Pycharm project. PYSimpleGUI is located in "venv" but not in "C".

After creating the spec file I create the exe with pyinstaller. It was suggested to use --hidden-import=PySimpleGUI as additional flag, which I did do, but I still got the same error. I also made sure python is added to my PATH, but maybe I did something wrong there? Tha path I used is the one where python is installed: C:\Users\Username\AppData\Local\Programs\Python\Python39\Lib\site-packages is that right?

I am completely stuck and can't find any helpful information. How do I solve this issue? Also important: I do not have admin rights on my computer, so installing stuff is always linked to me having to call the support desk...

If more information about this project is needed, let me know.

Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
Carina
  • 217
  • 4
  • 11

2 Answers2

0

Usually, modules not found tend to be the issues with virtual environment. Python uses those venvs as some sort of folders where it stores the Python interpreter and packages installed with pip. If you have an error saying some module is not found, you should either install it on your current environment or switch to the one where ot is already installed. For more details, I recommend you to take a look at this tutorial how to use and setup them.

Additionally, you do not need to compile Python code if you can afford relying on the interpreter installed. If you know your target audience has the interpreter installed (an interpreter is usually shipped with various Linux distributives), then you can just give them your source code or even pycache (.pyc) files that it can interpret as well.

  • that doesn't really help me. Pycharm creates the venv automatically and every package I use is automatically saved in the venv, which is why i specified the path to venv, but also to the original location of python and some packages, to be sure. Your second suggestion does not work for me, as non of my coworkers have any experience with code. They want an executable. – Carina Oct 06 '22 at 08:27
0

I tried three different things at the same time, one of them seemed to have solved the problem:

1.) update pip with the following commands in the PyCharm Terminal

pip install --upgrade PySimpleGUI

2.) update PySimpleGUI with the following commands in the PyCharm Terminal

C:\Users\Username\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip

3.) add python39 to PATH

I checked again and I did have \Python39\Scripts in my PATH, but not \Python39 itself, so I added it. The way to do it on windows is to search for "environment variables" (Umgegungsvariablen in german), edit the "Path" Variable (double click or click and press edit, which opens a new window), then add new Path (mine is C:\Users\Username\AppData\Local\Programs\Python\Python39) I sort them with Python39 being above Python39\Scripts.

This solved my problem with PySimpleGUI, my program started as expected, but then ran into another missing module error (xlsxwriter not found), which - fair enough - was not imported. (interestingly when running the code in pycharm I didn't need xlsxwriter). I imported it, added it to venv, and when starting the program again, the error showed up even before showing the GUI. I then upgraded xlsxwriter with

 pip install --upgrade xlsxwriter

I again created the .spec file and ran pyinstaller to create the exe. This time it worked.

Now I only have issues left which are not connected to missing modules (just variable referenced before assigned).

Carina
  • 217
  • 4
  • 11