I need to create an executable python app package containing all dependencies, including those that cannot be installed using pip (like gtk or other native modules). I must create Linux and Windows versions of this package. The problem is, I cannot find any way to create such package/executable. There are tools like py2exe or cx_Freeze, but they fail when including pygtk and other system dependent modules.
I just cannot believe there is no production ready solution, which allows python developers to do such obvious and trivial tasks.
Related
I want to deploy an executable (.exe) from my python2.7 project with everything included. I have seen pyinstaller and py2exe but the problem is that my project uses a lot of third-party packages that are not supported by default. What is the best choice for such cases? Is there any other distribution packager that could be used?
Thank you
The executable creation packages should be able to grab 3rd party packages if they're installed. Sometimes you have to specify what to include if the library abuses Python's importing system or it's not a "pure Python" package. For example, I would sometimes have to specifically include lxml to get py2exe to pick it up properly.
The py2exe project for Python 2 hasn't been updated in quite a long time, so I would certainly recommend one of the alternatives: PyInstaller, cx_freeze or bb_freeze.
I have only seen issues with MSVCP90.dll when using non pure Python packages, such as wxPython. Normally you can add that in your setup.py to include it. If that doesn't work, then you could also add it using an installer utility like NSIS. Or you may just have to state in your README that your app depends on Microsoft's C++ redistributable and include a link to it.
I developed my first webserver app in Python.
It's a but unusual, because it does not only depend on python modules (like tornado) but also on some proprietary C++ libs wrapped using SWIG.
And now it's time to deliver it (to Linux platform).
Due to dependency on C++ lib, just sending sources with requirements.txt does not seem enough. The only workaround would be to have exact Linux installation to ensure binary compatibility of the lib. But in this case there will be problems with LD_PATH etc.
Another option is to write setup.py to create sdist and then deploy it with pip install.
Unfortunately that would mean I have to kill all instances of the server before installing my package. The workaround would be to use virtualenv for each instance though.
But maybe I'm missing something much simpler?
If you need the package to be installed by some user the easiest way will be to write the setup.py - but no just with simple setup function like most of installers. If you look at some packages, they have very complicated setup.py scripts which builds many things and C extensions with installation scripts for many external dependences.
The LD_PATH problem you can solve like this. If your application have an entry-point like some script which you save in python's bin directory (or system /usr/bin) you override LD_PATH like export LD_PATH="/my/path:$LD_PATH".
If your package is system service, like some servers or daemons, you can write system package, for example debian package or rpm. Debian has a lot of scripts and mechanism to point out the dependencies with packages.
So, if you need some system libraries on the list you write it down in package source and debian will install them when you will be installing your package. For example your package have dependencies for SWIG and other DEV modules, and your C extension will be built properly.
I made a wxPython app for Mac and packaged it with py2app. Two people have already said they can't get it to launch, with the following error message:
ImportError: dlopen(/Users/username/Desktop/MCManager.app/Contents/Resources/lib/python2.6/wx/_core_.so, 2): Library not loaded: /usr/lib/libwx_macud-2.8.0.dylib
Referenced from: /Users/username/Desktop/MCManager.app/Contents/Resources/lib/python2.6/wx/_core_.so
Reason: image not found
I have only been able to test the app on Mac 10.6.7. Both of the people having the problem are using 10.7.x. Has anyone else had this issue, or know what it means? It seems from the message that it's trying unsuccessfully to load the wx library, but the wx library should be in the app
s Resources folder, correct?
Here's my setup file:
#! /usr/bin/env python
import py2app
from setuptools import setup
setup(
options = dict(
py2app = dict(
iconfile = 'MCManager.icns',
packages = 'wx',
site_packages = True,
plist = dict(
CFBundleName = "MCManager",
CFBundleShortVersionString = "1.2.2",
CFBundleGetInfoString = "MCManager 1.2.2",
CFBundleExecutable = "MCManager",
CFBundleIdentifier = "net.sourceforge.mcmanager",
),
),
),
app = ['ScriptUnix.py']
)
I run it with arch -i386 python26 filename.py py2app, (arch because I can't get Python to run 32-bit without arch, and 2.6 because, very very long story short, I can't use 2.7 with py2app).
The problem is that you're building a semi-standalone app. As the docs explain in various places, if you're using a "vendor Python", meaning any of the Python versions that came pre-installed with OS X, py2app cannot build a standalone app. For example:
If the --semi-standalone option or a vendor Python is used, then the Python.framework is ignored. All other vendor files (those in /usr/ or /System/ excluding /usr/local/) are also excluded.
So, it does not package up the wx libraries in /usr/lib, because those are vendor libraries. Instead, it just links to the existing ones. There are no such libraries on a standard OS X 10.7 system. Even if there were, the fact that you end up explicitly linking to the 2.8.0 version from 10.6 means it probably wouldn't work on later systems.
What you need to do is to get those wx libraries copied into your .app bundle, and reference them from there. And py2app will not do that for you if you run it with your vendor Python. Which means you have three choices:
Use a separate Python installation.
Trick py2app into building a standalone app anyway, possibly by hacking up the py2app sources.
Bundle the app yourself (or use a different tool).
The best answer is usually #1. In your comments, you say that you were able to install Python 2.7.3 (presumably from python.org?), and you were able to install py2app for the vendor 2.6, but that you weren't able to install py2app for the custom 2.7.3. That sounds highly implausible. (If you were able to install 2.7.3 somehow, it should be installed into directories that you have access to.) But, even if it's true, it doesn't matter; you can install Python packages into a user-specific site-packages directory, under your home directory. You don't need admin rights for that. And in fact, most Unix software is designed to work that way.
An even easier way to do that is to use virtualenv. Yes, I know, you can't install it, but you don't have to. If you read the docs, there's even a whole set of instructions on how to bootstrap a virtualenv on a system where you can't install anything. The result is your own personal Python installation, based on the system 2.7.3, but that you have total control over. So you can install py2app there. (There are a few notes about using py2app and virtualenv together, which you should read about in the py2app docs.)
If you can't or won't do any of those things, then py2app can't do what you want, at least not out of the box. But it's open source. And there are even comments in the source explaining why it doesn't try to make standalone builds from system Python. And most of the really tricky stuff is separated out into separate packages (like macholib and altgraph), so you should be able to understand py2app itself, well enough to hack together a standalone package that works for your specific app. (That's a lot easier than modifying p2app to fix the underlying problem in a fully general way.)
Or you could look at other tools that do similar things as py2app. Try searching PyPI for py2app or freeze and see what comes up. You can generally install packages into your home directory, or run them without installing them, so start playing with whatever looks promising and see if it solves your problem.
Finally making a legitimate mac installer for my product. I've made a successful Windows installer with Inno installer. I'm not sure how to do this in Mac.
This must happen:
-Python is installed
-Wx is Installed
-Py Serial is installed
-Program is copied
-Shortcut is made.
I was doing this with Bash scripts before, but my customers having been complaining about those. Perhaps X-code package maker is the solution? I know the recommended method is "just copy files" but these libraries must be installed somehow.
Thanks in advance!
Unless I am using Fink for installing packages, I usually just download the .tar.gz file from the source and install it from terminal inside the unzipped folder containing the install.py file. Terminal command:
sudo python ./setup.py install
If you would like, I can show you how to set up and use Fink, which is another easy way to install packages / libraries.
tl;dr: py2app will make a self-contained application bundle out of your Python scripts, making it real easy to employ the 'just copy files' installation process. The libraries you need are bundled into the app bundle itself, so they don't need to be installed systemwide.
Also check out Optimizing for Mac OS X from the wxPython wiki; it gives good tips on using py2app and other useful information on building a Mac-friendly Python application.
On OS X, programs are generally installed through one of three ways: the Mac App Store, a package installer (.pkg/.mpkg), or a copyable application bundle on a disk image (.app in a .dmg). Each has its strengths and weaknesses.
The Mac App Store requires that you subscribe to Apple's restrictions and requirements, and may be a good choice for apps expecting wider distribution (though, nowadays, it can be a good way to reach that wider audience easily). Copyable application bundles are by far the simplest installation method pre-App Store, and still remain one of the more popular ways to install programs. Finally, an Installer package is a user-friendly way to install more complex programs requiring more than a simple application bundle (e.g. system services, files in particular directories, system-dependent components, advanced installation logic, etc.). I should note, though, that do exist complex applications which ship as application bundles and perform the bulk of their 'installation' at first run.
My experience with the Mac App Store is limited, so I won't talk about it. You can find more details at the official website.
Python is quite amenable to being shipped as an application bundle. You can use py2app to automatically create an application bundle for the program, and then drop that bundle into a Mac disk image (.dmg) using Disk Utility to create a complete installation package. This doesn't support making shortcuts, but on OS X it is much more usual for users to just drop the app into /Applications and make the necessary dock shortcut themselves if they want.
The next way is to make a metapackage (.mpkg) which will be installed using the OS X standard Installer utility. This is in line with what users will expect from a Mac application. IIRC, both Mac Python and wxPython ship as .pkg already, which should make it easier to integrate them into a metapackage. bdist_mpkg can help with making packages for pyserial and your own program, which can be added to the metapackage. Finally, using the third-party dockutil script, you can automatically add a dock shortcut. Note, however, that installers generally do not add shortcuts to the dock; it is more usual to have a program installed to the /Applications directory.`
I'm new to python and I'm writing my first program. I would like after I finish to be able to run the program from the source code on a windows or mac machine. My program has dependencies on 3rd party modules.
I read about virtualenv but I don't think it helps me because it says it's not relocatable and it's not cross-platform (see Making Environments Relocatable http://pypi.python.org/pypi/virtualenv).
The best scenario is to install the 3rd party modules locally in my project, aka xcopy installation.
I will be really surprised if python doesn't support this easily especially since it promotes simplicity and frictionless programming.
You can do what you want, you just have to make sure that the directory containing your third-party modules is on the python path.
There's no requirement to install modules system-wide.
Note, while packaging your whole app with py2exe may not be an option, you can use it to make a simple launcher environment. You make a script with imports your module/package/whatever and launches the main() entry-point. Package this with py2exe but keep your application code outside this, as python code or an egg. I do something similar where I read a .pth text file to learn what paths to add to the sys.path in order to import my application code.
Simply, that's generally not how python works. Modules are installed site-wide and used that way. Are you familiar with pip and/or easy_install? Those + pypi let you automatically install dependencies no matter what you need.
If you want to create a standalone executable typically you'd use py2exe, py2app or something like that. Then you would have no dependencies on python at all.
I also found about zc.buildout that can be used to include dependencies in an automatic way.