How to package a python script for Windows OS(.exe)? - python

I want to distribute my open source python tool.
I created an install shell script for linux systems. What is the easiest way to create a graphical easy to use installer for Windows OS?
PS: I would consider the ability to add shortcut on desktop as a plus point.

Py2Exe is still the best way I'm aware of. You can do tricky things if you're someone like Dropbox.
EDIT If you're looking for advice on creating an installer, start here

Related

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 distribute a Python script to non-developers on Windows

Say I made Python script with a GUI, which depends on a few libraries (e.g. Pandas). I want to share this application with users who know nothing about programming, and who are used to simply click an install file or open an executable.
What are the options for bundling my script, its dependencies, and the Python runtime together so that my users can "just" use it ? This can be either as an executable, or an online app.
EDIT : some users pointed to this page as a duplicate. This obviously true, but most answers are pretty old. I'm looking for up-to-date solutions as of 2019.
I have been using PyInstaller for a while now, seems like it would do exactly what you
want.
You need to use pyinstaller package
PyInstaller freezes (packages) Python applications into stand-alone
executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and
AIX.
pyinstaller.org

package a software for Windows with wine

I use Esky/cx_freeze to package a python program for different OS. When I have to do it for windows, I use Windows 7 on VirtualBox.
However, I find this method pretty unpleasant and heavy. So I wonder, is there a way to package programs for Windows through Wine ?
I would basically need to install all the libraries I need, then run some commands like "python setup.py bdist_esky".
I know the cx_freeze doc doesn't advice this, but I'm trying to find a better way to package my software. I wonder if someone has a better option.

Using wxwidgets to create a gui

I need to create a cross platform GUI mainly targetting Windows and Linux. I finally decided that I would use the wxWidgets library to get it done since it has a less restrictive license and has a python binding. However I just wanted to know if I would have to install wxPython on every computer that needs to run my GUI. Because I really cant ask the user to go to the site and install wxPython in order to get my software working. Is there any way around this? IS there any other good cross platform GUI toolkit apart from Java,Qt and wxWidgets?
This explains how to use wxPython together with pyinstaller, allowing you to build an .exe file for Windows.
On linux you can use .deb files and add python-wxgtk2.8 to the dependencies; If a user doesn't use .deb files, he should probably know how to install wxPython :)
However I just wanted to know if I would have to install wxPython on every computer that needs to run my GUI.
If you don't want to manually install wxPython on each computer, you'd have to include all of the wxPython library with your distribution (i.e. the contents of the wx directory which is probably somewhere in site-packages or dist-packages), and any other libraries they depend on which aren't typically installed by default.
On Linux, you might just be able to use ldd on wxPython's .pyd files to find out what they depend on, and you can do something similar for Windows.
If it's loading stuff via dlopen(3) or the Windows equivalent, it's a bit more complicated. You might have to try it, wait to see what missing libs it complains about, and add those to the distro.

Releasing a wxPython App: Give out scripts or compile in Exe, etc?

I have a wxPython application that is almost done & I would like to place it in my portfolio. I have to consider when someone attempts to run my app that they may not have Python, or wxPython, so if they just click the main script/python file its not going to run, right?
How should I distribute my app (how do you distribute ur apps) so that it can be run & also so that it could be run on the 3 major OS's (Unix, Windows, MacOSX)?
I know of py2exe for releasing under windows, but what can I use for Unix & MacOSX to compile the program? Whats the easiest way?
Use Gui2exe and compress with UPX to get unpacked size down.
For a setup file(exe) with uinstall info Inno-Setup is good.
I have use this with wxpython several times and got it to work on all windows versions.
For Gui2exe use optimize(2) - compressed(2) - Bundle files(3)
Bundle files(3) is the most stable,
Bundle files(1) make one big exe-file.
For one exe-file is better as last step to use Inno-Setup
You can use py2exe for Windows and py2app for Mac. PyInstaller works for Windows and Linux. Personally, I use GUI2Exe, which wraps all three and makes them a little easier to use. Note: I don't have a Mac, so I haven't tried it with that. You can check out my series on freezing Python here:
http://www.blog.pythonlibrary.org/2010/08/10/a-pyinstaller-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/31/another-gui2exe-tutorial-build-a-binary-series/
There are a couple others on the blog too.
I suggest both, script for all platforms and frozen binary for lazy windows users.
To answer your latest question, you don't compile python. Python is an interpreted language, it gets compiled on the fly when run. A python frozen binary is actually the python interpreter with your script hardcoded in it. And frozen binaries are windows-only, AFAIK. Besides, Unix and MacOS (usually) come with python pre-installed.

Categories

Resources