Ship Python script in a self-contained package? (Linux, Mac, Windows) - python

I wrote a script which I wish to deploy on Mac OS, Windows and Linux clients. While most Mac and Linux machines have some version of Python, Windows does not. Adding to this there's a module partly written in C that I wish to include.
Currently I'm looking into freezing the code (e.g. py2exe or PyInstaller), but this will get tedious on changes.
Is there a good alternative to ship the script in one self-contained package?

Related

Using Docker and Pyinstaller to distribute my application

I have a Python application built with PyQt5. My current OS is Windows 11 and I'm able to distribute my software to Windows users using PyInstaller and Inno Setup (to create the installer). However, I would like to distribute it to MacOS and Linux users too.
From PyInstaller's documentation:
PyInstaller is tested against Windows, Mac OS X, and GNU/Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a GNU/Linux app you run it in GNU/Linux, etc. PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD but testing against them is not part of our continuous integration tests.
As you can see, PyInstaller is not cross-compiler. So, I'm wondering the best way to distribute my software to all OS using PyInstaller. Actually, I'm able to create .deb using WSL2, but no clues for .dmg for MacOS.
I've already read that I can use virtual machines to achieve this, but I would like some alternatives (maybe Docker?)
Thanks!

Using pyWin32 without installing it

Is it possible to use pyWin32 without installing it?
I would like to include it into python's interpreter folder.
I have managed to use Python interpreter without installing it (simply installing it and copy&pasting installed directory into my product).
I need also the same with pyWin32.
My objective is:
Client receives a folder with a script (batch) which will run python program in a console. The client does not have to install python, pywin32, nothing. What he needs is to copy and paste my product and run the console-based program.
Is it possible?
My objective is: Client receives a folder with a script (batch) which
will run python program in a console. The client does not have to
install python, pywin32, nothing. What he needs is to copy and paste
my product and run the console-based program.
I would suggest something along the lines of using pyinstaller or any other python code to executable converter.
http://www.pyinstaller.org/
PyInstaller is a program that freezes (packages) Python programs into
stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD,
Solaris and AIX. Its main advantages over similar tools are that
PyInstaller works with Python 2.7 and 3.3—3.5, it builds smaller
executables thanks to transparent compression, it is fully
multi-platform, and use the OS support to load the dynamic libraries,
thus ensuring full compatibility.
To me it seems this would suit your/your clients needs quite well. Furthermore pyinstaller is easy to use.

Will users be able to open my program without downloading Python?

I'm making a program in python, but once I'm finished with the program, will the users have to download the python environment in order to use my program, or will it work without the python environment once compiled? Also, will it automatically be cross-platform or will I have to download a conversion program to make it work for Linux, Mac OS and Windows? I'm new to the language so this is confusing me.
Many Linux systems come with Python installed already. However, there are some tools to help if it is not:
pyinstaller for Windows, Linux, and Mac OS X (does not work for Python 3)
bbfreeze for Windows and Linux
py2exe for Windows
Freeze for Linux
py2app for Mac OS X
Have a look at py2exe for windows, linux and mac is likely to have it preinstalled.
They would need a python interpreter to use your program unless you turn your python script into a windows executable. One way of doing that is by using Py2exe
It depends on what 3rd party libraries you include in your program.
For example I never managed to make a windows executable with the PyQt lib,
by using py2exe. But this was 2-3 years ago and things might have changed.
Also don't hardcode paths in your program and make use of functions like os.path.join
Don't make assumptions about config files and stuff. Do check on runtime the platform
your program is running on and act accordingly.
In general, your biggest problem will be the Windows platform.

Python application builder/packager

I'm writing a program in python using PySide(PyQt) and I want to distribute it to friends and family when I'm finished. I have looked at other posts in stack overflow, but I can't seem to find any good ones showing an easy solution(command line or otherwise) that will create an executable for my program to be run on other computers who don't have python or Qt etc. I'm running Ubuntu right now, however I would like to be able to package for windows as well.
Edit: I wrote all the Qt interface in my python script, so the whole project is contained in the one script.
I have used PyInstaller to create executables for scripts using PyQt4 under Windows without any trouble. Though I have not used it on Linux, it claims Linux (and OSX) support as well. You may need to create your Windows binaries in a Windows system or through Wine according to the FAQ:
Can I package Windows binaries while running under Linux?
No, this
is not supported. Please use Wine for this, PyInstaller runs fine in
Wine. You may also want to have a look at this thread in the
mailinglist. In version 1.4 we had build in some support for this, but
it showed to work only half. It would require some Windows system on
another partition and would only work for pure Python programs. As
soon as you want a decent GUI (gtk, qt, wx), you would need to install
Windows libraries anyhow. So it's much easier to just use Wine.

Portable Python (Mac -> Windows)

I have a lovely Macbook now, and I'm enjoying coding on the move. I'm also enjoying coding in Python. However, I'd like to distribute the end result to friends using Windows, as an executable.
I know that Py2Exe does this, but I don't know how portable Python is across operating systems. Can anyone offer any advice? I'm using PyGame too.
Many thanks
The Python scripts are reasonably portable, as long as the interpreter and relevant libraries are installed. Generated .exe and .app files are not.
Py2exe generates Windows executables, so they will only work on the Windows Platform. The FAQ at http://www.py2exe.org/index.cgi/FAQ has more information on how it all works. Essentially it provides what is needed to run on Win9x as well as more current platforms. NOTE: the FAQ mentions some potential gotchas with character encodings and the work arounds.
With python, it is common enough on Unix based systems, as several Linux distributions have their custom maintenance scripts written in the language. So the Python scripts will be just as portable as Ruby scripts, etc. As long as the target machine has the interpreter and you are not using external programs that are only on one type of platform, others will be able to use your work.
Personally I experienced huge difficult with all the Exe builder, py2exe , cx_freeze etc. Bugs and errors all the time , keep displaying an issue with atexit module.
I find just by including the python distro way more convinient. There is one more advantage beside ease of use.
Each time you build an EXE for a python app, what you essential do is include the core of the python installation but only with the modules your app is using. But even in that case your app may increase from a mere few Kbs that the a python module is to more than 15 mbs because of the inclusion of python installation.
Of course installing the whole python will take more space but each time you send your python apps they will be only few kbs long. Plus you want have to go to the hussle of bundling the exe each time you change even a coma to your python app. Or I think you do , I dont know if just replacing the py module can help you avoid this.
In any case installing python and pygame is as easy as installing any other application in windows. In linux via synaptic is also extremly easy.
MACOS is abit tricky though. MACOS already come with python pre installed, Snow leopard has 2.6.1 python installed. However if you app is using a python later than that and include the install of python with your app, you will have to instruct the user to set via "GET INFO -> open with" the python launcher app which is responsible for launcing python apps to use your version of python and not the onboard default 2.6.1 version, Its not difficult and it only takes a few seconds, even a clueless user can do this.
Python is extremely portable, python pygame apps cannot only run unchanged to the three major platform , Windows , MACOS ,Linux . They can even run on mobile and portable devices as well. If you need to build app that runs across platform , python is dead easy and highly recomended.
If you are planning to include Linux in your portability criteria, it's worth remembering that many distributions still package 2.6 (or even 2.5), and will probably be a version behind in the 3.x series as well (I'm assuming your using 2.x given the PyGame requirement though).
Versions of PyGame seem to vary quite heavily between distros as well.

Categories