Malcolm2608
Malcolm2608

Reputation: 349

How do you make an installer for your python program?

I'm new to python, but I was thinking about making a program with python to give to my friends. They don't know much about computers so if I asked them to install python by them selves they wouldn't be able to do it, but what if I could make an installer that downloads some version of python that only has what is needed for my file to run and make an exe file that would run the .py file in its own python interpreter. I also did a Google search and saw the freezing applications I could use to make the code into exe files to distribute (cx_freeze I use python 3.2), but not all of my friends have Windows computers and I rather have my program so in each new version it auto updates by making a patch to .py file and not completely re-installing it.

I am not looking for anything to make a stand alone executable. Just some kind of installer that bundles a minimalistic version of the python version you're using. And an option to have an exe that is just a link to run the python file in the portable python interpreter, just for windows and a .sh file that would do the same for linux.

Upvotes: 34

Views: 68965

Answers (7)

Anjali singh
Anjali singh

Reputation: 1

You can use auto-py-to-exe python package, this is an easy GUI based .py to .exe creator.

  1. pip install auto-py-to-exe
  2. open it with cmd command :
    auto-py-to-exe

check this site : [1]: https://pypi.org/project/auto-py-to-exe/

Upvotes: 0

David Leon
David Leon

Reputation: 101

Regarding Installer Program (for windows).

I think what you are looking for is InstallForge. This is a tool that you can use to build your own installation wizard. This website pythonguis is a tutorial for PyInstaller and InstallForge. You can skip the PyInstaller part and go towards the middle to view the InstallForge tutorial if you are not interested in making your py application executable using PyInstaller, although I recommended it as many have mentioned.

InstallForge has the ability to make your own install wizard which you can program to install your py files or executables in the directory you want and create a shortcut to the application you want your friends to run.

If you don't have to download the python interpreter version as you stated, if you bundle your py files with Pyinstaller, it will already include the python interpreter version, making it easier to bundle within your InstallForge. Another StackOverflow thread here, explains how you can install python using the command line, assuming you already have the python interpreter installation. To actually download python from the web in an automated way I was not able to find info on a system designed for this, although I'm sure it's not impossible if you get creative.

After you figured out how you want to bundle, and install your program, you can program your system to auto-update itself with the PyUpdater python module found in pip

Upvotes: 10

Great Owl
Great Owl

Reputation: 61

Use nuitka. Nuitka is THE python compiler. You can install it from

pip -v install nuitka

You can create a single executable by (for windows)

py -m nuitka --enable-plugin=tk-inter --show-scons --show-progress --onefile --remove-output --warn-implicit-exceptions --warn-unusual-code --windows-disable-console--windows-icon-from-ico=ICON_PATH --windows-uac-admin main.py

or

py -m nuitka --enable-plugin=tk-inter --show-scons --show-progress --onefile --remove-output --warn-implicit-exceptions --warn-unusual-code --disable-console --linux-onefile-icon=ICON_PATH main.py

Upvotes: 4

Jothin kumar
Jothin kumar

Reputation: 21

You can create an inno setup installer.
Steps:

  1. Build a pyinstaller executable with the following commands:
    pip install pyinstaller
    pyinstaller --onefile yourfile.py
  2. Use innosetup to create installer.
    Refer Inno setup docs or This blog for more info

Upvotes: 1

LethDev2019
LethDev2019

Reputation: 126

Pyinstaller is a good option to convert them to an windows executable. You can install it in cmd.exe as admin and run pip install pyinstaller or pip install --pre pyinstaller.

you can then run it using pyinstaller. (sorry that i can't supply a automated script i wrote after a system restore. I'll write it again soon using pyqt5)

syntax

--onefile - puts the program and it's files into a exe.

--onedir - put your program into a directory (folder) (faster than --onefile as it does not need to extract files)

-c - create a console app.

-w - create an app without the console.

-i "[Path to .ico or exe with icon. e.g C:\Files\CODE\Icon.ico]" - create an app without the console.

you can read the rest here.

You can then get inno setup and create an offline installer.

If you need a web installer (it downloads a file and extracts it.) I am currently writing one and would be glad to create one for you.

Upvotes: 9

Prof. Falken
Prof. Falken

Reputation: 24937

I am shocked that no answer mentions that py2exe now supports both Python 2.x and Python 3.x

https://pypi.python.org/pypi/py2exe#downloads

Upvotes: 8

Abhranil Das
Abhranil Das

Reputation: 5916

Python is an interpreted, not a compiled language. So any standalone program you may want to distribute must bundle the entire interpreter inside it plus the libraries you used. This will result in an enormous file size for a single program. Also, this huge install cannot be used to run other python programs. An only marginally more complicated, but far better solution than this, is to just install the interpreter once and run any python program with it.

I understand that the point of your question was to make a standalone executable, so I know I'm not answering it. But not being able to create executable standalones is one of the caveats of interpreted languages. However, a fundamental point here is about the whole objective of an interpreted language, which is a single interpreter with all the generic functions required to run any python code (which now happily needn't be any longer than they need to be). So you see, it's not really a caveat, this was the whole intention of interpreted languages. You might finally find a way to create a standalone python executable that runs on your friends' computers, but that would defeat the entire framework and idea behind an interpreted language.

Upvotes: 1

Related Questions