-1

I have developed a quite complex Python script (about 2000 lines of code) that finds, filters, edits and opens hundreds of .csv and .xlsx files in several location. It creates differnet output files: .csv and .xlsx files with merged data, statistics, etc. Also creates automatically many figures with plots and log file. It all works fine. Scripts starts with a easygui button box asking the user a few inputs.

I wanted to make a self executable file that can be run in other machine without Python installed. And this works fine using PyInstaller. It takes about 3 to 5 minutes to complete the script. At the end of the script a easygui box message informs the user that the script finished successfully.

But after a few seconds the script starts again automatically. Only option to stop it is to cancel the easygui box (cross in corner) or kill the script in the background.

The code I use to create the stand alone executable script is:

PyInstaller.__main__.run(['My_script.py','--onefile','--windowed','--log-level=DEBUG', '--debug=all'])

How can I make my code such that when script is finished is not restarting itself again? Thanks for any hint!

1 Answers1

-1

How about you use docker instead of PyInstaller? you can use python docker images (depending on your hardware limitations) and then you can run your script just as easily in an isolated enivrement.

1st step:

Create your dockerfile. Here's a quick example for your usecase.

FROM python:3.9

WORKDIR /script-path

COPY My_script.py .
COPY requirements.txt .

RUN pip install --no-cache-dir pyinstaller

CMD ["python", "My_script.py", "--onefile", "--windowed", "--log-level=DEBUG", "--debug=all"]

The requirements.txt file should contain the necessary packages that are used in your script.

2nd step:

Build your docker image, for example by using :

docker build -t my-script-image .

Note that you should be in the same directory where your Dockerfile is located.

3rd step:

Run your image :

 docker run --rm my-script-image

the --rm flag is to remove the image once it exits.

Hope that helps.