How to distribute a simple desktop application in Python? - python

This is my first attempt in hosting one of my Python projects and after reading multiple tutorials, I am confused on which steps are necessary (i.e. writing it into a python package, freezing it as an .exe, etc)? A lot of the tutorials seem to be overkill for what I feel should be an easy task.
Currently, I have two .py files (one for the gui and one for the back-end) and few miscellaneous data files. The program works for Python 2 and 3.
The end goal would be to have a file or package that another person would be able to download from my website that has a desktop icon executable that prompts the gui. The package will need to be able to install a list of requirements (I can do this through a requirements.txt file?).
Would anyone know what the "bare bones" structure should be? (i.e. would I need to write it as a package or would freezing it with a req instllation pre-pended to the gui file work?)
Thanks!

Related

Creating executable Python scripts for wider audiences

I have read several posts regarding creating .exe files from Python scripts using tools like cx_freeze or pyinstaller and read a few articles which basically admit to having the same issues as the posts do - namely, the .exe files are simply too large (sometimes in the hundreds of MB). I have tried this myself on a script and simply because libraries like Numpy and Pandas were packaged into it, the executable became massive.
This is a bit of real world scenario so I am taking a shot here at asking about this but is there no way to create solutions for teams who do NOT have coding experience? The only options I can think of are:
Require all users to have Python and the related libraries installed on their systems and train them in running the scripts.
Perhaps push the script to a cloud service and run the script from there (though this may be an issue when it needs to connect to inhouse databases and other source systems).
Accept the size of the .exe file and save it on shared drives and go for a lunch break every time you need to run it.

How to convieve of a cross platform python script

I have made a python interactive script project containing a few directories with project files and a main python script.
The script does the work of batch processing scientific images for biological systematics.
I wrote os agnostic code, but I was thinking about trying to package/freeze the script as a cli utility that a (more or less)lay person could download and use.
I have been reading about packaging and freezing techniques in python and the more I read the more I feel I'm confused. (I'm linux user)
Am I conceiving of this script as a utility correctly? Is is worth it/possible to pass command line args to an .exe, and should I package/freeze the files for this kind of interactive cli script?
I don't have a lot of experience with windows. I'm looking for advice/pointer where to look next/search.
You are on the correct path, but you need to understand a little more about python packaging to know how to proceed.
You are right that you need to package your code with setup tools. This will make it cake to install the package for others and will let python decide where to properly put things. -including script utilities/non-code files-
Setuptools has special support built in JUST FOR SCRIPTS! that will let you pass arguments, ect..
However, in packaging the code, you must understand that what you are really doing is making it a library that can be installed with pip. Therefore, that python script utility that you wrote will be treated as a library by setuptools. Setuptools will have you make a separate script file to import your new library and call the script main() function.
I know that you were already using this manual, and that's fantastic. Everything you need to first set up and understand a python package is in there. RTFM up a storm.
As I understand it, you can then look more into freezing the package (and register it with Pypi) for other systems once you have a handle on packaging.
note: use scripts keyword in setup tools to specify your script

Universalizing my program/Making it accessible to other users

So I am creating a program that takes input, processes the data, then puts it in Excel. In order to do this, I am using the "xlwt" package (and possibly xlrd). How do I then give this program to other people without making them download python and the packages associated with my program? I considered utilizing an online python interpreter and giving the username/password to my coworkers, but xlwt isn't on any of the ones I've tried, and they don't offer a way (that I can see) to download new packages.
You would have to compile the code into an exe file. The py2exe library can help you out with this

Bundling an application, hide sources/libs?

This question is not about how to bundle a python application into a exe, or a binary. I can (almost) figure that by myself, with all the doc on the internet.
My question is more about what the final user will be able to see about my program. And for my personal culture.
For example, with cx_freeze, if I try to compile my app, I end up with a build directory. Inside, I have the binary of my app, let's call it "gui". But around, I have a bunch of *.so files.
Basically, the user can see every lib I used to build my app. I thought (maybe naively) that if I could create a unique binary file, all the libs would be included in the binary, and so, not "visible" by the user.
Do I think right or is it completely wrong ? Is it possible to bundle all the libs into one single binary, and mask them ? (I know cx_freeze can't handle a single bundle file).
You may want to consider pyinstaller. With the --onefile switch you can bundle everything into one file. However, it only fully supports python X2. This is a good tutorial to get started with it .
If you cannot use pyinstaller, you may want to try to use the answer posted here.
EDIT:
After having read the cx_freeze documentation, it turns out that you cannot bundle everything into a single exe. You will have to create a self extracting file with 7zip or IEXPRESS (if you are on Windows) that just unpacks all of your .so files.

How to run a Python script in something other than cmd?

I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.

Categories

Resources