Distributing Programs Written in Python [duplicate] - python

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Distributing Python programs
I have several source codes for some GUI programs I made in Python. I'd like to distribute them. However, I'd like to make it as easy as possible for the end user to get the program up and running. What are the common way's of going about this problem?
This is in reference to Windows XP and on.

All noteworthy linux distributions and Mac OS come shipped with some version of Python. Windows don't have Python installed by default, so you must install it separately in order to run a Python module. Of course the installed Python version must be the same as your program (version 2 or 3).
The easiest way to distribute your program is to just distribute the source code (e.g. send your module by email or upload it somewhere) but in that case, the target PC must have Python installed and meet the dependencies. An even better solution (at least for the community) is to upload your program as a package on PyPi. More info for that procedure can be found HERE.
In some cases there are reasons that prevent you from using these options. For example you can't install python and/or the dependencies (no root/admin account). If that is the case, you can bundle your module(s) along with everything else that is required to run your program (e.g python*.dll on windows). As far as i know the basic options for this kind of distribution are the following ones:
PyInstaller
briefcase
fbs
PyOxidizer
nuitka --standalone
py2app (only for Mac OS)
cx_Freeze
freeze
py2exe
cython --embed
Another approach would be to use Portable Python or in case of Linux/BSD StaticPython
Note : Not all of the aforementioned tools run on all platforms or/and support Python3. Check their documentation.
Unmaintained ones
bbFreeze
esky (unmaintained)
vendorID
gui2exe

You want py2exe, which is an extension of the distutils package.
http://www.py2exe.org/

Related

Remove dependencies when compiling .py to .exe [duplicate]

I need to package my Python application, its dependencies, and Python itself into a single MSI installer for distribution to users. The end result should desirably be:
Python is installed in the standard location
the package and its dependencies are installed in a separate directory (possibly site-packages)
the installation directory should contain the Python uncompressed and a standalone executable is not required
Kind of a dup of this question about how to make a python into an executable.
It boils down to:
py2exe on windows, Freeze on Linux, and
py2app on Mac.
I use PyInstaller (the svn version) to create a stand-alone version of my program that includes Python and all the dependencies. It takes a little fiddling to get it to work right and include everything (as does py2exe and other similar programs, see this question), but then it works very well.
You then need to create an installer. NSIS Works great for that and is free, but it creates .exe files not .msi. If .msi is not necessary, I highly recommend it. Otherwise check out the answers to this question for other options.
My company uses the free InnoSetup tool. It is a moderately complex program that has tons of flexibility for building installers for windows. I believe that it creates .exe and not .msi files, however. InnoSetup is not python specific but we have created an installer for one of our products that installs python along with dependencies to locations specified by the user at install time.
I've had much better results with dependencies and custom folder structures using pyinstaller, and it lets you find and specify hidden imports and hooks for larger dependencies like numpy and scipy. Also a PITA, though.
py2exe will make windows executables with python bundled in.
py2exe is the best way to do this. It's a bit of a PITA to use, but the end result works very well.
Ok, I have used py2exe before and it works perfectly except for one thing... It only works on executable windows machines. I then learned about Jython which turn a python script into a .Jar file. Which as you know is executable from any machine that has Java ("To your latest running version") installed. Which is great because both unix, windows, and ios (Most of the time) Run java. That means its executable from all of the following machines. As long as they run Java. No need for "py2mac + py2exe + freeze" just to run on all operating systems. Just Jython
For more information on how it works and how you can use it click here.
http://www.jython.org/

How to automate the installation of python interpreter in any operating system [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 months ago.
The community reviewed whether to reopen this question 7 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I want to create a single executable from my Python project. A user should be able to download and run it without needing Python installed. If I were just distributing a package, I could use pip, wheel, and PyPI to build and distribute it, but this requires that the user has Python and knows how to install packages. What can I use to build a self-contained executable from a Python project?
There are several different ways of doing this.
The first -- and likely most common -- way is to use "freeze" style programs. These programs work by bundling together Python and your program, essentially combining them into a single executable:
PyInstaller:
Website || Repo || PyPi
Supports Python 3.7 - 3.10 on Windows, Mac, and Linux.
cx_Freeze:
Website || Repo || PyPi
Supports Python 3.6 - 3.10 on Windows, Mac, and Linux.
py2exe:
Website || Repo || PyPi
Supports Python 3.7 - 3.10 on Windows only.
py2app:
Website || Repo || PyPi
Supports Python 3.6 - 3.10 on Macs only.
The main thing to keep in mind is that these types of programs will generally only produce an exe for the operating system you run it in. So for example, running Pyinstaller in Windows will produce a Windows exe, but running Pyinstaller in Linux will produce a Linux exe. If you want to produce an exe for multiple operating systems, you will have to look into using virtual machines or something like Wine.
Of course, that's not the only way of doing things:
pynsist:
Website || Repo || PyPi
Pynsist will create a Windows installer for your program which will directly install Python on the user's computer instead of bundling it with your code and create shortcuts that link to your Python script.
The pynsist tool itself requires Python 3.5+ to run, but supports bundling any version of Python with your program.
Pynsist will create Windows installers only, but can be run from Windows, Mac, and Linux. See their FAQ for more details.
Nuitka:
Website || Repo (Github mirror) || PyPi
Nuitka will literally compile your Python code and produce an exe (as opposed to the other projects, which simply include Python) to try and speed up your code. As a side effect, you'll also get a handy exe you can distribute. Note that you need to have a C++ compiler available on your system.
Supports Python 2.6 - 2.7 and Python 3.3 - 3.10 on Windows, Mac, and Linux.
cython:
Website || Repo || PyPi
Cython is similar to Nuitka in that it is a Python compiler. However, instead of directly compiling your code, it'll compile it to C. You can then take that C code and turn your code into an exe. You'll need to have a C compiler available on your system.
Supports Python 2.7 and Python 3.3 - 3.11 on Windows, Mac, and Linux.
My personal preference is to use PyInstaller since it was the easiest for me to get up and running, was designed to work nicely with various popular libraries such as numpy or pygame, and has great compatibility with various OSes and Python versions.
However, I've also successfully built various exes using cx_Freeze without too much difficulty, so you should also consider trying that program out.
I haven't yet had a chance to to try pynist, Nuitka, or Cython extensively, but they seem like pretty interesting and innovative solutions. If you run into trouble using the first group of programs, it might be worthwhile to try one of these three. Since they work fundamentally differently then the Pyinstaller/cx_freeze-style programs, they might succeed in those odd edge cases where the first group fails.
In particular, I think pynist is a good way of sidestepping the entire issue of distributing your code altogether: Macs and Linux already have native support for Python, and just installing Python on Windows might genuinely be the cleanest solution. (The downside is now that you need to worry about targeting multiple versions of Python + installing libraries).
Nuitka and Cython (in my limited experience) seem to work fairly well. Again, I haven't tested them extensively myself, and so my main observation is that they seem to take much longer to produce an exe then the "freeze" style programs do.
All this being said, converting your Python program into an executable isn't necessarily the only way of distributing your code. To learn more about what other options are available, see the following links:
https://packaging.python.org/overview/#packaging-python-applications
https://docs.python-guide.org/shipping/packaging/#for-linux-distributions
pyinstaller is under active development as of July 2022. You can see the latest changes on GitHub. It supports for Windows, Linux, and MacOS; 32 and 64-bit. It supports Python versions 2.6, 2.7, and 3.3+.
auto-py-to-exe is a GUI for PyInstaller.

Portable Python/IPython

I am currently starting a business where I will be providing support to clients directly on their business offices. I need to be able to go to different computers and be able to run custom python scripts, my question is if there's a way to make my python environment portable?
Assuming that your users are running Windows, I see two options here.
If you have already defined which scripts you will be running, compile them into exe files using py2exe, that way you can just plug a USB and run them as needed. (the caveat is that some antivirus will automatically block the unsigned executables)
The other option is to use WinPython, that is a full python environment with a lot of packages already preinstalled that ives in it's own directory. In case you need to install a new package, just use the Powershell or CMD that comes with it and use the preinstalled "pip".
I found something interesting here Portable Python. I use that method to create portable Python 3.9 and 3.10 and everything works so have a look.

How to make my python 3 desktop application portable?

I have tried portable python but the latest version is 3.2.5. (need 3.6+)
I cannot install libraries on it, even the get-pip.py doesn't work.
I'm trying to figure out how to make my project portable on windows systems that do not have python installed.
Also I want the minimum possible libraries(core python modules) to keep the project as lean as possible,
I would go with cx_Freeze - multiplatform module for freezing your Python script in a way that allows you to open it on other Windows machines even if they do not have Python installed. It got very nice and clear documentation also: http://cx-freeze.readthedocs.io/en/latest/ and works a bit better on Windows machines then alternative PyInstaller from my experience (which has interesting option of one-file-package, but in many cases leads to security warnings due to some dirty hacks used to obtain that feature).
However, it may not be enough if you are using some specific modules in your app, as for example matplotlib, dash, etc modules are very hard to pack correctly with Freezer.
I have found a solution to my own question after a couple of days.
I did not want to create an executable for my project but I wanted a portable python folder so that I can add libraries to it as and when I need.
The recent version of portable python is WinPython.
I had to delete some unnecessary files out of it though.
It's size is about 77 mb after extracting
https://winpython.github.io/
https://sourceforge.net/projects/winpython/files/WinPython_3.6/3.6.5.0/WinPython64-3.6.5.0Zero.exe/download

How does mercurial work without Python installed?

I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that.
How does it work?
Also, is it possible to force Mercurial run on IronPython and will it be compatible?
Thank you.
The Mercurial windows installer is packaged using py2exe. This places the python interpreter as a DLL inside of a file called "library.zip".
On my machine, it is placed in "C:\Program Files\TortoiseHg\library.zip"
This zip file also contains the python libraries that are required by mercurial.
For a detailed description of how mercurial is packaged for windows, see the developer page describing building windows installer.
Since there is a "library.zip"(9MB), Mercurial's Windows binary package maybe made by py2exe, py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
Others have answered the first question -- let me give a guess about the second part.
Mercurial will normally use some C extensions for speed. You cannot use those with IronPython.
But we also ship pure Python versions of these modules, and depending on how much IronPython implements of a standard Python 2.4 environment, those modules could be compatible. I have seen reports on IRC about Jython (the Java port of Python) being able to do a few operations using the pure modules. You should download Mercurial and take a look at the mercurial/pure folder. These modules simply has to be moved up one directory level to be found, the setup.py script can do this if you pass the --pure flag. Please see its source or come talk with us on the Mercurial mailinglist/IRC.
Mercurial bundles the necessary python binaries within it, I believe.

Categories

Resources