October 21, 2024
Chicago 12, Melborne City, USA
python

How to create an installer that installs Python and all dependencies for my Python project on a fresh machine?


P.S I am not looking to make a single executable file to run the whole program(although I will need it later) but rather a file that will install all the dependencies (if it does not exist already)
I have a Python project with the following structure:

A main script (main.py) in the root folder which starts the application:

if __name__ == '__main__':
    script_dir = os.path.dirname(os.path.abspath(__file__))
    os.chdir(script_dir)

    myRoot = tk.Tk()
    myApp = Pk_MainApp(myRoot)
    myApp.Run()

The project relies on several dependencies (e.g., opencv, tkinter, xml.etree.ElementTree, and others).

I have many imports across different .py files, and the project also includes subfolders containing other scripts.

I generated a requirements.txt file using pipreqs, but it seems incomplete — not all imports are captured. My goal is to create an installer (batch file or .exe) that will:

Install Python on a "virgin" machine (one that has no Python or libraries installed).
Install all the necessary Python libraries and dependencies listed in requirements.txt.
Ensure that after running this installer, the project can be executed without any manual setup, simply by running main.py.
My current approach involved running:

bash
Copy code
pipreqs path/to/my/folder –force
However, I noticed that it didn’t catch all of the required dependencies, such as tkinter.

Question:
Is there a way to automate the installation of Python itself, along with all required libraries and dependencies for my project? Ideally, I’d like to put everything on a USB drive and have a single .bat or .exe that, when run, will install Python, the required dependencies, and allow the project to run. What’s the best way to achieve this?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video