24

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.

BardiaB
  • 9
  • 3
Malcolm2608
  • 249
  • 1
  • 2
  • 4
  • The vote-to-close looms, but before it hits: look [here](http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm). For cross-platform, consider `easy-install`. – MrGomez Mar 31 '12 at 23:39
  • I'd recommend `cx_Freeze`. It has a major advantage of decreasing the chances of being detected as malware. Well, at least to me. – NameError Dec 23 '21 at 06:27

7 Answers7

8

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.

Community
  • 1
  • 1
LethDev2019
  • 116
  • 1
  • 5
6

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

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
5

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

David Leon
  • 51
  • 1
  • 2
2

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
Great Owl
  • 23
  • 4
1

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
Jothin kumar
  • 21
  • 1
  • 6
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – jmoerdyk Jan 25 '22 at 18:20
1

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.

Abhranil Das
  • 5,702
  • 6
  • 35
  • 42
  • 7
    I'm sorry but I wasn't looking for that , but that you anyways . :D – Malcolm2608 Apr 01 '12 at 08:06
  • An option would be to bundle your project specific files together with the interpreter you want in an installation package (e.g. using http://nsis.sourceforge.net/Main_Page). That way you can have them install python (or check if it already exists) and your project specific files too. – Moe Apr 01 '12 at 08:10
  • This is not an useful answer, it does not provide a solution. – Markus Bawidamann Dec 22 '20 at 20:06
  • I have a little python tool that I wronge and I used pyinstaller to create an exe and that (as you claim) "HUGE" one file exe is 10 megabytes, which is truly tiny ;-) This includes even some libraries, so no problem at all. – Markus Bawidamann Dec 24 '20 at 04:09
  • Then what is the proper procedure for creating a functional python program that is distributable and consistent for use on windows? – user7420124 Jan 03 '22 at 17:57
0

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/