1

I want to create a single executable from my Python project which uses tkinter. A user should be able to download and run it without needing Python installed. What can I use to build a self-contained executable from a Python project?

my question is somewhat similar to this one but I didn't find what I was looking for there.

I have a folder which looks like this:

-project/
   -script.py
   -res/
      -image1.jpg
      -image2.jpg
      -image3.jpg

In my script.py I am using the images from the res folder in my tkinter UI and I want to create an executable out of this script. what would be the best way to tackle this problem?

  • Does this answer your question? [Bundling data files with PyInstaller (--onefile)](https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile) – Delrius Euphoria Jun 26 '21 at 11:13

2 Answers2

1

You can try using PyInstaller

PyInstaller - How to convert to .exe

1. Installation

The pyinstaller module makes you able to create a standalone exe file for pc from a python script, so that you can use it on other computers than do not have python or your python version.

To install pyinstaller: pip install

2. Create an exe

After you installed pyinstaller, go in the folder where your python script to be transformed in exe is and type in the command line (go in the address bar on top of the window and type cmd). Then type :

pyinstaller yourscript.py

where your script is the name of your file.

You will find a folder called “dist” where there is a folder called yourscript (if the name of your script was this) where there are many files and the exe file that will allow you to run the script also on other computer. You just have to copy the whole folder.

3. What to do if there are images

If you use images, that are in the same folder, for example, you can copy manually into the folder made by pyinstaller or you can run this command to make it do it for you:

pyinstaller –add-data “*.png;.” yourscript.py

This way you will see that in the folder where your exe is there are also the png files (all of them, if you want just one do not put the asterisc, but the whole name of the file.

External links - PyInstaller

PCM
  • 2,881
  • 2
  • 8
  • 30
0

Use a bundler like Pyinstaller.

Pyinstaller website
Include images in Pyinstaller

Note: If you are having issues with tkinter and pyinstaller take a look at this: Problems with Pyinstaller with tkinter app on python 3.5

maxicarlos08
  • 121
  • 1
  • 7