How do I deploy a Python desktop application? - python

I have started on a personal python application that runs on the desktop. I am using wxPython as a GUI toolkit. Should there be a demand for this type of application, I would possibly like to commercialize it.
I have no knowledge of deploying "real-life" Python applications, though I have used py2exe in the past with varied success. How would I obfuscate the code? Can I somehow deploy only the bytecode?
An ideal solution would not jeopardize my intellectual property (source code), would not require a direct installation of Python (though I'm sure it will need to have some embedded interpreter), and would be cross-platform (Windows, Mac, and Linux). Does anyone know of any tools or resources in this area?
Thanks.

You can distribute the compiled Python bytecode (.pyc files) instead of the source. You can't prevent decompilation in Python (or any other language, really). You could use an obfuscator like pyobfuscate to make it more annoying for competitors to decipher your decompiled source.
As Alex Martelli says in this thread, if you want to keep your code a secret, you shouldn't run it on other people's machines.
IIRC, the last time I used cx_Freeze it created a DLL for Windows that removed the necessity for a native Python installation. This is at least worth checking out.

Wow, there are a lot of questions in there:
It is possible to run the bytecode (.pyc) file directly from the Python interpreter, but I haven't seen any bytecode obfuscation tools available.
I'm not aware of any "all in one" deployment solution, but:
For Windows you could use NSIS(http://nsis.sourceforge.net/Main_Page). The problem here is that while OSX/*nix comes with python, Windows doesn't. If you're not willing to build a binary with py2exe, I'm not sure what the licensing issues would be surrounding distribution of the Python runtime environment (not to mention the technical ones).
You could package up the OS X distribution using the "bundle" format, and *NIX has it's own conventions for installing software-- typically a "make install" script.
Hope that was helpful.

Maybe IronPython can provide something for you? I bet those .exe/.dll-files can be pretty locked down. Not sure how such features work on mono, thus no idea how this works on Linux/OS X...

I have been using py2exe with good success on Windows. The code needs to be modified a bit so that the code analysis picks up all modules needed, but apart from that, it works.
As for Linux, there are several important distribution formats:
DEB (Debian, Ubuntu and other derivatives)
RPM (RedHat, Fedora, openSuSE)
DEBs aren't particularly difficult to make, especially when you're already using distutils/setuptools. Some hints are given in the policy document, examples for packaging Python applications can be found in the repository.
I don't have any experience with RPM, but I'm sure there are enough examples to be found.

Try to use scraZ obfuscator (http://scraZ.me).
This is obfuscator for bytecode, not for source code.
Free version have good, but not perfect obfuscation methods.
PRO version have very very strong protection for bytecode.
(after bytecode obfuscation a decompilation is impossible)

Related

Compile Python Code In Objective-C [duplicate]

So it's a new millennium; Apple has waved their hand; it's now legal to include a Python interpreter in an iPhone (App Store) app.
How does one go about doing this? All the existing discussion (unsurprisingly) refers to jailbreaking. (Older question: Can I write native iPhone apps using Python)
My goal here isn't to write a PyObjC app, but to write a regular ObjC app that runs Python as an embedded library. The Python code will then call back to native Cocoa code. It's the "control logic is Python code" pattern.
Is there a guide to getting Python built in XCode, so that my iPhone app can link it? Preferably a stripped-down Python, since I won't need 90% of the standard library.
I can probably figure out the threading and Python-extension API; I've done that on MacOS. But only using command-line compilers, not XCode.
It doesn't really matter how you build Python -- you don't need to build it in Xcode, for example -- but what does matter is the product of that build.
Namely, you are going to need to build something like libPython.a that can be statically linked into your application. Once you have a .a, that can be added to the Xcode project for your application(s) and, from there, it'll be linked and signed just like the rest of your app.
IIRC (it has been a while since I've built python by hand) the out-of-the-box python will build a libPython.a (and a bunch of other libraries), if you configure it correctly.
Of course, your second issue is going to be cross-compiling python for ARM from your 86 box. Python is an autoconf based project and autoconf is a pain in the butt for cross-compilation.
As you correctly state, making it small will be critical.
Not surprising, either, is that you aren't the first person to want to do this, but not for iOS. Python has been squeezed into devices much less capable than those that run iOS. I found a thread with a bunch of links when googling about; it might be useful.
Also, you might want to join the pyobjc-dev list. While you aren't targeting a PyObjC based application (which, btw, is a good idea -- PyObjC has a long way to go before it'll be iOS friendly), the PyObjC community has been discussing this and Ronald, of anyone, is probably the most knowledgeable person in this particular area. Note that PyObjC will have to solve the embedded Python on iOS problem prior to porting PyObjC. Their prerequisite is your requirement, as it were.
I've put a very rough script up on github that fetches and builds python2.6.5 for iPhone and simulator.
http://github.com/cobbal/python-for-iphone
Work in progress
Somewhat depressing update nearly 2 years later: (copied from README on github)
This project never really got python running on the iPhone to my
satisfaction, and I can't recommend using it for any serious project
at this stage.
Most notably missing is pyobjc support (which turns out to be much
harder to port to iPhone since it relies on more platform-specific
code)
Also missing is the ability to statically compile modules, (all are
currently built as dylibs which works for development, but to my
knowledge wouldn't be allowed in the App Store)
At this point this project is mostly meant to be a starting point for
anyone smarter than me who wants to and can tackle the above issues.
I really wish it were practical to write apps entirely in Python, but
at this point it seems impossible.
I also started such a project. It comes with its own simplified compile script so there is no need to mess around with autoconf to get your cross compiled static library. It is able to build a completely dependency-free static library of Python with some common modules. It should be easily extensible.
https://github.com/albertz/python-embedded/

75 MB Helloworld with py2app !

I'm testing different languages to developp a desktop application for Mac&Windows.
I thought that Python+Wx worth a try so I wrote a simple hello world.
Then, I tried the py2app to package my application as a Mac application.
What a surprise to find that my hellworld.app weight as much as 75 MB !! (then I have an error at runtime but that's not the question)
Here is my question : is there a way to distribute a standalone wxPython application that weight less than a few MB ? (for instance, an adress book app).
(a Swing HelloWorld is around 3KB, plus around 20MB for the JRE)
Thank you
I would highly remmoend you using PyINstaller, which can be found here: link
it works like a chamr for me so far and it support most of the major libraries:
wxpython pyqt and even django (although i dont really understand the whole django support thing ;-) )
PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. Its main advantages over similar tools are that PyInstaller works with any version of Python since 2.2, 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.
The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. As an example, libraries like PyQt, Django or matplotlib are fully supported, without having to handle plugins or external data files manually. Check our compatibility list of SupportedPackages.
i hope this helps, good luck and tell if you need anymore help

desktop development language compiled binary or scripting language (windows)?

Does anyone use a scripting language only solution to produce a binary (.exe) to produce a commercial desktop application for windows or mac? e.g. Java, python etc. If so how do you distribute your app and does using a scripting language cause any problems with the installation?
I'm asking about users that can download an application and install it, they don't know about setting path variables, or changing there JAVA_HOME. The assumption for the PC are users with a consumer PC with windows (XP/Vista/7), not power users. (Or alternatively a mac type solution would be interesting to hear about to)
I have done this in a couple ways. One was to use Python and py2exe, and the other was to use Idle, a Lua-based "compilable" language, using InnoSetup to create installers.
I have had no problems with either, though I haven't used Idle for anything of any significant complexity --- its main advantage is the small size of the executable produced. With py2exe, you have to be careful to get all the dependencies included in the package, and I recommend testing it thoroughly on a clean installation of Windows before releasing. For example, when I used PyGTK with py2exe, I had to be very careful to get the theming files included in the package. It was not evident at first that I had missed them, since PyGTK found them in the installed version on the development machine.
I also had to be careful about installation paths, permissions, and startup directories, as well as licensing of the libraries I used, but that's nothing you wouldn't have to be concerned with in a more traditional compiled language. Other than the relatively large size of the installer, I've been very happy with py2exe and InnoSetup, and I'd recommend it.
Does anyone use anything else for shrink wrap apps on windows? e.g. Java, python etc.
Yes. I assume you're not really asking about Java, since that is so wide-spread. I can count quite a few Java applications that I use, and I don't operate in the "Enterprise" environment.
There are tools that allow you to ship Python code without shipping actual .py files and without needing the to actually have Python installed, so there are solutions for that as well. Since such tools exist I assume people do ship Python applications.
If so how do you distribute your app and does using a scripting language cause any problems with the installation?
What scripting language?

Distributing minimal python installation with application

My company is working on an application that is half Qt/C++ for the editor interface and half Django (via QtWebKit browser control) for the runtime. What we want to do is distribute a minimal python installation with our application.
For instance, our Mac app bundle would ideally be structured something like this:
TheApp.app/
Contents/
MacOS/
TheApp
Resources/
MinimalPythonInstallation/
On Windows:
C:\Program Files\TheApp\
TheApp.exe
MinimalPythonInstallation\
I've seen plenty of projects out there for distributing full Python applications such as py2app, py2exe, and PyInstaller. Those seem to have some of the features I'm looking for, but without the ability to just make a minimal python distribution. i.e. the python executable, Django, and the bare minimum of the python standard library needed by Django, our python code, etc.
Is there anything out there that can do what I'm looking for?
You can find the set of modules you need with modulefinder -- indeed, I believe that's a key part of what the systems you mention, like py2exe and PyInstaller, do for you, so I'm not clear why you want to "reinvent the wheel" -- care to clarify? Have you looked at exactly what e.g. PyInstaller puts in the executables it generates, and, if so, why isn't that good enough for you? If you explain this in detail, maybe there's some extra way we can help.
(PyInstaller is cross-platform, so, if you want to support Mac as well as Windows, it's probably the one you'll want, since py2exe is Windows-only).

Distribute a Python program with a minimal environment

I want to distribute a Python application to windows users who don't have Python or the correct Python version.
I have tried py2exe conversion but my Python program is really complex and involve code import on the fly by xmlrpc process so it is not suitable for py2exe.
The complete Python folder takes around 80MB but this includes docs and a lot of non-essential things.
Do you know if there exists a small package of a minimal Python interpreter I can include with my program ? Include a folder of 80MB is a bit big ;)
PyInstaller is a py2exe "competitor" that has many extras (such as being cross-platform, supporting popular third party packages "out of the box", and explicitly supporting advanced importing options) -- it might meet your needs. Just be sure to install the SVN trunk -- the existing (1.3) release is way, WAY obsolete (PyInstaller is under active development again since quite a while, but I can't convince the current maintainers to stop and do a RELEASE already -- they're kind of perfectionists and keep piling more and more great goodies, optimizations, enhancements, etc, into the SVN trunk instead;-).
Have a look at Portable Python. This will install a Python programming environment in a local folder. I am sure that you could strip many unwanted things off.
I recommend however that you give py2exe another chance.
..involve code import on the fly by xmlrpc process so it is not suitable for py2exe
Py2exe can deal with situations like this. You just have to tell it which modules are being imported at runtime, so that it includes them in the distribution. Your code should then be able to import from these modules dynamically.
püy2exe is bad and incompabilite to Windows 10 now.
I suggest you use BoxedApp Packer until 22 mb small without runtimes....
enter link description here
It is almost better than py2exe because py2exe need many py files and opened data files...

Categories