Using serial ports in a .exe (Windows)

I am using the serial library in a project that needs to be exported as an exe. The project works fine in the pycharm console environment, however, I get PyInstaller missing module error messaage in the warn- file. I have tried several suggestions to specify the location of the libraries, but nothing works. I have a virtual environment (.venv). I wonder if the serial drivers need to go through some installation process on the destination computer or something. Hoping to find someone who has used the serial library in an exe.

Please share the errors and warning you see.

Thank you for responding. I am not using most of the items listed so I am not sure why they are listed.

missing module named pwd - imported by posixpath (delayed, conditional, optional), shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named grp - imported by shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named posix - imported by os (conditional, optional), shutil (conditional), importlib._bootstrap_external (conditional), posixpath (optional)
missing module named resource - imported by posix (top-level)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional)
missing module named _posixsubprocess - imported by subprocess (conditional)
missing module named fcntl - imported by subprocess (optional)
missing module named ‘serial.tools’ - imported by serialmanager (top-level)
missing module named serial - imported by serialmanager (top-level)

All the other warning are safe to ignore as only needed on unix systems.

But these two are critical as they say that your .exe will have no serial code in it.

O e trick I use is to add imports of modules pyinstaller misses as explicit imports in my main module. In this case add

import serial
import serial.tools

Does that work when run as a script and as a .exe?

The new warn file is exactly the same and the .exe that is generated is the exact same size as the previous version. Both have new generation dates and times.

I have added both to the top of my main file “PSmain.py” like this:

import serial
import serial.tools

import tkinter as tk

from screens.controllerparams import ControllerParameters
from screens.commandsender import CommandSenderScreen
from serialmanager import SerialPortManager
from screens.mainscreen import MainScreen
from screens.flashscreen import FlashScreen
from screens.positionmanager import PositionManager

#from globalvariables import deviceconnected
import globalvariables
#import serial

Try running the PSmain.py outside of pycharm.

Do you have a venv that you have installed all your dependencies into to use to test the script?

Does it work?

Interestingly, it appears to do the same thing when running outside of python as running the exe on another computer. Just a flash by of a screen then colsed. I do have a virtual environment called .venv it is directly under the Scon V.54 directory.

What I suggest you do is work outside of pycharm, as I have no idea what its doing to help or hinder debugging this.

Write a batch file that does all the steps required to setup the venv.

rmdir /s /q tmp.venv
py -m venv create tmp.venv
tmp.venv\bin\python -m pip install <list-of-packages-from-pypi-you-use>
tmp.venv\bin\python PSmain.py

What happens?

First, thank you for all of your help. In your second line, don’t know what py means running it from a command prompt results in ‘py’ is not recognized as an internal or external command,
operable program or batch file. Is that short for python? in that case -m venv creates a path to should

I have discovered that if I try to run my program without pycharm , it can’t find ‘serial’. C:\Users\Orwill\PycharmProjects\Scon V.54>python PSmain.py results in No module named ‘serial’

I am going to continue trying to create the batch file you suggest. My virtual environment is ‘.venv’ will tmp.venv then be tmp…venv ? Would you please elobrate on tmp.venv.
Many thanks

The py.exe is installed as part of the python.org python windows installation.
Where did you install python from?

You can name the venv anything you like. .venv or tmp.venv are both ok.

I installed python from python.org, I generally avoid the Microsoft store. I would also like to be able to generate a Linux version of this program after I get it figured out. This is my first use of python.

Barry, Thank you for your help. I can now run my program outside of pycharm. I will have to work on the packages to include because it still will not install on a different machine.