Creating an actual, executable program from Python code - python

I very recently wrote a program for a friend where it simplifies some important daily calculations for him/her. Now, the problem I am having is that I want to compile the code into an executable program so that he/she can comfortably run it on their machine, perhaps with a simple graphical interface or whatnot.
I have tried using cx_Freeze with Python 3.3.0 64 bit but to no avail (the program simply refuses to start on their machine; I even tried generating an executable via 32-bit Python, but also to no avail). What I then thought was that I could perhaps generate an executable program via PyGame? But the fact of the matter is that I have never used any Python-related program except the IDLE, so I am not sure what to do and look for.
Another option would perhaps be to convert the Python 3.3.0 code to Python 2.x, but the problem is that I am not familiar with Python 2.x and neither is there any automated converter available (as far as I know). I was wondering whether anyone of you could direct me to any good sources/links, since those I have been ferociously Googling are rather inconcrete.

You could just use py2exe. It is compatible with python 3. I have seen tutorials for it on youtube.

You could try embedding it in a C program, and compiling that for your executable. A decent tutorial is in the python docs at http://docs.python.org/2/extending/embedding.html

PyInstaller "is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX" and gives you one standalone executable file.
Even as a noob Python user I have succeeded to pack my app using PyInstaller (relatively) easily.

Related

python - Converting a VPython program into an exe

I am currently making a physics simulation using VPython, and want to turn it into an exe file, using pyinstaller, so that it can run on a Mac laptop.
Essentially, I have two questions - one short and one long.
Short question: will the exe file I create using pyinstaller run on a Mac laptop if I created it using windows?
Long question:
I converted my program into an exe, but it doesn't work. Here is a screen shot of the error:
Pyinstaller error
Good news: I think I have found a solution to my problem from another question on stackoverflow, but I am a newbie and can't comprehend a single word of the answer. And, the answer uses anaconda, but I am using pycharm... in other words I am completely lost.
Link to answer: how to make vpython .exe using pyinstaller
In order to convert a Python program into an executable file (i.e. “freeze” the program), you’ll need something like PyInstaller. PyInstaller and related projects (such as py2exe) take Python programs, and package them into *.exe files for your users to run. The end result is a standalone executable file that doesn’t require Python to be installed on the end user’s system.
Keep in mind though, that these methods of “freezing” a Python program can incur a fairly large startup penalty and/or bloat your executable size. The end result is an executable that may take a significantly longer time to start up than usual, and may be much larger than you would expect it to be.

Managing Python 3 code with SCons

at work I have the task to convert a large library with Python 2.7 Code to Python 3.x.
This library contains a lot of scripts and extensions made with boost python for C++.
All of this is built with SCons which does not work with a Python 3.x interpreter, but now me and my supervisor want to know if there is a way around this.
The SConstruct file contains expressions with sys.version to determine the correct module-directories to import (numpy etc.). I do not know how to use SCons or the syntax, so I can not give a lot of information about this topic.
Can we use SCons to build Python 3 Code with the given extensions or do we have to wait until SCons is compatible with Python 3?
At the time of writing this, there are plans to support both Python 2.7 and 3.x in a single branch/version. Work on this feature has started, but it will take some more time to reach this goal.
So it looks as if your best bet would be to start right away. SCons itself should run fine under Python 2.7 for compiling the Boost extensions. The problem in your case are the added checks and detection mechanisms for deriving paths and module names from the version of the current Python interpreter.
Since you can't give any more detail about this process, my answer is somewhat vague here, sorry. In principle you'd have to find the place in the SConstructs/SConscripts where the version of the currently running Python interpreter is determined. Just hardcode this to the 3.x version that you have installed on the machine additionally, and keep your fingers crossed that the rest will work automatically.
Note how there is a clear separation here between "compiling code for a Python version" vs "compiling code under a Python version".
In general, a better understanding of SCons internal workings and basic principles might be helpful. If you find the time, check out the UserGuide ( http://scons.org/doc/production/HTML/scons-user.html ) or consult our user mailing list ( see http://scons.org/lists.php ) for larger questions and discussions.

Compiling python script to standalone program

Is it in any way possible too compile a python script into a standalone program, that would be possible to run on another machine that does not have python installed?
Preferably in a way that the script (or, compiled program) would be able to be installed on other machines, so that it's not just a random file but an actual program that can be launched from the start menu on windows.
Being able to do this in windows is the minimum, but if any cross-platform method exists that would be a big plus.
Any help appreciated.
Actually, there are at least two decisions, as of April, 2015 both work with both Python 2 and 3.
Both I have personally used and can confirm working.
1. cx_Freeze
http://cx-freeze.sourceforge.net/
Works with Windows, OS X and Linux, although you have to compile (or should I say, "freeze") your app on each system. You may use compile your code on different machines or just use virtual machine. Beware that you should use 32-bit Python if you want your app to run on 32-bit systems and compile against it!
2. py2exe
http://www.py2exe.org/
It has added support of Python 3 just recently.
The advantage is that it is possible to wrap the whole program in single executable, while with cx_Freeze you usually end up with Python itself in one file, all your dlls and pythons libraries in separate files and all your code in library.zip file, which is compiled to .pyc files, but this operation is easily reversable, so beware that some of your users might easily hack your software!
The main disadvantage of py2exe is that it is Windows-only.

will python code written in windows work in linux?

I would like to write some Python code in Windows using QtPy. But before I do that I'd like to know that I can use the code I wrote in Python. I understand that the complied program won't work due to different platforms but will there be any issues with regards to the *.py files I write in windows vs linux?
I've been trying to install QtPy on my Mint installation and I just don't know what the problem is. Which is why I wanna go this route.
I'd also like my code to work on the raspberry pi.
Could you guys advise me to this end?
Thanks!
Mostly, yes, as long as you keep to using the tools Python provides you and don't write code that is platform specific.
Use os.path.join() to build paths, for example. Open files in binary mode when you deal with binary data, text mode when it's text data. Etc.
Python code itself is platform agnostic; the interpreter on Linux can read python code written on Windows just fine and vice versa.
The general rule of thumb is to pay attention to the documentation of the modules you are using; any platform specific gotchas should be documented.
It depends on what your code does. Most packages work in both windows and linux however some such as signal only work in windows and are not portable. But in the python docs it will say what platforms a given package works in.

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