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.
Related
This is something I've been researching for past few hours but so far nothing come out of it.
Basically I have software that use Python 2.5.5. It does not have QT module in it.
So in my attempt to install it I did this.
Downloaded executable QT PyQt4-4.10.2-gpl-Py2.7-Qt4.8.4-x64. Run Exe. It installed in python 2.7 site-packages.
Then I moved that folder to my software Python 2.5.5. Now there was no site-packages folder so I created it.
Next step was to go over this instruction http://docs.python.org/2/install/ and use Alternate installation: Windows (the prefix scheme) with my file location from inside program. But I cant run python setup.py install --prefix="\Temp\Python" (with my location of python) because python is not defined and so on. I'm pretty sure thats the wrong way to do it. So how or where do I look for information as to how to do it? The software itself dont have any documentation.
Thanks, bye.
That binary version of PyQt4 only supports python2.7, so no matter what you do, you won't get it to run with python2.5.
The last PyQt4 version with a binary for python2.5 is PyQt4.9.4, so if you want to have any chance of making this work you should try with this version.
Note however that the software you distribute like this will also only run on python2.5.
I'm writing a program on a computer running Ubuntu with an x86-64 processor that needs to run on a computer running OS X with an x86 processor. I'm probably not going to be able to do any kind of library installation, so a venv is pretty much the only option I know of.
How can I make one targeted for that platform?
If I can't, is there a better way to ship the libraries with the program?
Virtualenvs are not a packaging mechanism. There is no reason a virtualenv should ever leave the computer it was created on. It won't work, the virtualenv is 100% specific to your OS, CPU architecture, Python version, etc.
There are a number of solutions for packaging. The old and still current way is specifying dependencies in setup.py, and running setup.py install on the target machine. Note that this can happen inside a virtualenv, you just have to create the virtualenv and run setup.py in there. Both virtualenv and the standard library venv in 3.3 provide ways of doing this automatically after virtualenv creation.
If you absolutely must create a binary distribution (e.g. because you need an extension module and the end user doesn't have a compiler), you need an egg or a wheel or one of the .py-to-binary converters (py2exe, PyInstaller, cx_Freeze, etc.). You will need access to an OS X machine to create that. And at least the wheel and the egg are usually installed anyway, so using them doesn't save you any of this hassle. That's because they are formats for binary distribution, their primary purpose is pushing the build step from the end user to the developers, not to remove the installation step.
In summary: Just create a script which creates a virtualenv and installs your application as well as the required libraries.
You can't do this as the python executable you use on Ubuntu is not going to run on OS X, even if the architecture is the same.
If you're trying to distribute a Python program without installation, you could look at something like PyInstaller. You'll still need access to a machine running OS X to generate the app bundle, but you should be able to package up everything into a .app bundle that is launched like a standard OS X application.
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 am trying to create a .pkg installer for a python application (specifically Spyderlib). This is not an app but a python package and a command line executable that have to be copied to specific locations.
However, the location depends on the version of OSX. I'm only targeting 10.6 and 10.7 but they come with different versions of python (2.6 and 2.7) so the install path is different.
Using bdist_mpkg I was able to create a Mac mpkg in 10.7 which installs correctly and can be edited with PackageMaker. Now I want to know how I can edit this package so that it detects the version of OSX and sets the install target path correctly.
I understand that I can use shell scripts to do pre and post-installation jobs, however I haven't been able to find examples of how to do this and how a script could but used to set the install target for the files in the mpkg.
Alternatively, it may be that this is possible to do directly from PackageMaker, but i was not able to see anything to this effect (and the documentation seems quite superficial).
So I would like to know how this could be done. It would also be really helpful to see some examples for other software packages.
You don't need any scripts - you can do that with Package Manager alone - the Package Manager GUI allows you to tag packages as installable (enabled) and selected based on conditions such as OS version (in Choices under Requirements)
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.