What would be the optimal way to develop a basic graphical application for Windows based on a Python console script? It would be great if the solution could be distributed as a standalone directory, containing the .exe file.
As far as I understand your question, you want to write a graphical windows application in Python, to do this I suggest using wxPython and then py2exe to create a standalone exe that can run on any machine without requiring python to be installed
The following tutorial shows everything step by step: Quickly Creating Professional
Looking Application Using wxPython, py2exe and InnoSetup
I would recommend that you use IronPython, which is Microsoft's implementation of Python for the .NET framework.
Tkinter is quick and easy to use. Tkinter is in the Python standard library.
Related
This question already has answers here:
Create a directly-executable cross-platform GUI app using Python
(13 answers)
How to deploy Python to Windows users?
(4 answers)
Create a single executable from a Python project [closed]
(3 answers)
Closed 9 years ago.
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right.
How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
Auto PY to EXE - A .py to .exe converter using a simple graphical interface built using Eel and PyInstaller in Python.
py2exe is probably what you want, but it only works on Windows.
PyInstaller works on Windows and Linux.
Py2app works on the Mac.
I found this presentation to be very helpfull.
How I Distribute Python applications on Windows - py2exe & InnoSetup
From the site:
There are many deployment options for
Python code. I'll share what has
worked well for me on Windows,
packaging command line tools and
services using py2exe and InnoSetup.
I'll demonstrate a simple build script
which creates windows binaries and an
InnoSetup installer in one step. In
addition, I'll go over common errors
which come up when using py2exe and
hints on troubleshooting them. This is
a short talk, so there will be a
follow-up Open Space session to share
experience and help each other solve
distribution problems.
Also known as Frozen Binaries but not the same as as the output of a true compiler- they run byte code through a virtual machine (PVM). Run the same as a compiled program just larger because the program is being compiled along with the PVM. Py2exe can freeze standalone programs that use the tkinter, PMW, wxPython, and PyGTK GUI libraties; programs that use the pygame game programming toolkit; win32com client programs; and more.
The Stackless Python system is a standard CPython implementation variant that does not save state on the C language call stack. This makes Python more easy to port to small stack architectures, provides efficient multiprocessing options, and fosters novel programming structures such as coroutines. Other systems of study that are working on future development: Pyrex is working on the Cython system, the Parrot project, the PyPy is working on replacing the PVM altogether, and of course the founder of Python is working with Google to get Python to run 5 times faster than C with the Unladen Swallow project. In short, py2exe is the easiest and Cython is more efficient for now until these projects improve the Python Virtual Machine (PVM) for standalone files.
Not on the freehackers list is gui2exe which can be used to build standalone Windows executables, Linux applications and Mac OS application bundles and plugins starting from Python scripts.
Use cx_Freeze to make exe your python program
py2exe:
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
See a short list of python packaging tools on FreeHackers.org.
Not sure if this is the location to ask this, so please close or move as appropriate.
We are bundling Python2.7 64-bit and a number of python libraries (GDAL, SciPy, Numpy) into an application (py2app / pyinstaller). I wonder if it is possible to create a stand alone terminal that has access to the installed libraries, but not the system libraries. This would be akin to FWTools.
The goal is to allow the user to open a command prompt within the GUI and have access to all of the libraries within the application a la a virtual environment.
For example, a user with GDAL 1.8 installed could download this application, launch a stand alone command line and utilize our build of gdal 1.9.1 from within the application.
Any references would be appreciated as we are just considering this approach and are unsure of the feasibility.
We are writing this in python.
There isn't a very easy way to embed a console / terminal into any of the GUI frameworks. The closest I've heard of is PyGTK's VteTerminal. You might be able to use Python's curses library, but I haven't been able to find any good ways to wrap that in a GUI either.
If all you want is a Python shell, you might be able to use wxPython's PyShell or PyCrust widgets. Those are pretty straight-forward.
I'm talking about deploying Python-made, GUI-based, desktop applications via .app and .exe format for OSX and Windows. As far as I've gone into Python, I've only seen it as an application that runs on the Terminal / Command Prompt. I know that it is possible to create a user interface for it using various offerings on the internet (wxPython?). I just want to see how it passess off as a way for a developer to create mac and windows applications with as little code difference as possible.
I find that Python is a very good language for GUI programming. As you have stated, you can use the bindings for wxWidgets (wxPython), but there's also a binding for just about every other cross-platform GUI toolkit you can think of (Tk, Qt, GTK, FLTK, etc.). These GUI toolkits should allow you to make a program that will run unmodified on most OSs.
In terms of Python OS compatibility, it will behave virtually the same on all OSs, except for one or two modules such as mmap.
Using py2exe, py2app, or similar tools, you can embed a Python interpreter (along with your program's bytecode and it's dependencies) within an executable, making it easy to distribute an application. An end user can then open the program as they are used to. If you want the "security" of a compiled language, Python will not be the best language for you to use (but I prefer readability over safety :).
Another thing to consider with cross-platformness is what OS specific features you plan on using. Most GUI toolkits will not support things such as Microsoft's DWM (though you can use OS features through ctypes).
I think what you're looking for is PyQT and Tkinter. Both are GUI Libraries for use with Python. Both are cross-platform. Further, for packaging up .exe and .app for distribution, look at py2exe and py2app.
For Windows, the easiest approach is py2exe. There's also a similar project for MacOS. It's called py2app. Most GUI frameworks are cross platform. Just check their documentation, or even the home pages should have it.
Make good use of the os module. It has many function that will handle cross platform situations. A common example is file paths. When you build a path should it be backslash or forward slash? os.path.join handles that for you, and works based on which operating system it's running on. You shouldn't have to modify your code at all when shipping from OS to OS. It should run on Linux just as well, naturally.
By the way, MacOS often comes prepackaged with Python. As long as it's a somewhat recent version this can make the difference between a Hello World script being 1kb and 30mb, so avoid packaging Python with it. Unfortunately Windows isn't as well equip. Consider an option for "I already have Python installed" when downloading the exe.
I'm setting up a scripted build of a cross-platform python app (Python 3) and I'd like to create all the distributables from linux. Is that possible?
Short answer: no
I've been doing something similiar recently (using cx_Freeze with Python 3). If you set up Python inside Wine, you can generate a Windows build, but I had to copy some DLLs in before it worked properly (cx_Freeze calls a Windows API function that's not implemented in Wine). I've not run into any way of packaging applications for Macs without actually having a Mac.
Perhaps someone should set up a community build service so people could build distributables for different platforms for each other. That doesn't get round the problem of testing, though.
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.