I'm running Python 2.5 on a PowerBook with Mac OS 10.4. I downloaded and installed PyObjC from source so it would compile (I thought) against the right version of Python, then installed DjangoKit using python setup.py install. Everything seemed to be working, and I was able to build an application. But when I ran that app, it produced an error about the version of the SQLite libraries being used (2 instead of 3) and missing libraries.
I gave up on Python 2.5, re-installed PyObjC and DjangoKit for 2.4 and tried again. Same error.
Just for grins, I copied the app over to my wife's laptop (she has a MacBook Pro). The result was, of course, a new error about the platform. No universal binaries? Really?
I'm sure there are options, or something, that I'm leaving out when I build the app. This was mostly an experiment, and I was in a hurry, so I gave up easily and just installed the django code I wanted on an existing (Linux) web server and let her use that instead of messing with a desktop application.
Has anyone else had more success building portable Python apps, esp. with django, on Mac OS X?
Updated:
Of course I knew better than to post in frustration when I posted this originally. In my haste, I didn't post sample code, the error message, or much of the rest of the information I would have wanted if I was the DjangoKit author trying to help someone out. Nonetheless, Tom did some digging anyway and offered suggestions. Others did as well. Thanks! I finally found time to follow up, and am coming closer to an answer.
Here are the full details:
The application is very, very simple. The model just contains 2 classes for creating an index of a pile of Cook's Illustrated magazine we have laying around the house. There is no front-end, since the admin views already provide the functionality she wanted. I thought I would be cute and bundle it as a desktop app for Ms. PyMOTW, instead of setting the app up on my web server. I have packaged the sample code and placed it on my server.
I have included 2 separate setup.py files (setup.py and djangokit_setup.py). I couldn't package the source using the DjangoKit version of setup:
$ python djangokit_setup.py sdist --force-manifest
Loading 'initial_data' fixtures...
No fixtures found.
running sdist
warning: sdist: missing required meta-data: name, url
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
error: dist/Cook's Illustrated Index.app/Contents/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5/Frameworks/Python.framework/Versions/2.5: File name too long
I only seem to get the error if my dist directory includes the application, too. Otherwise I get a minimal package with the name 'UNKNOWN'. So, the tarball was packaged with a regular distutils setup.py. That's not a big problem, since it is easy to use separate files.
When I ran python djangokit_setup.py py2app, the first time it reported this error:
*** creating application bundle: Cook's Illustrated Index ***
error: can't copy 'media': doesn't exist or not a regular file
I eventually figured out (guessed) that even though I don't have any external media, I need a media directory at the same level in the directory tree as the setup file. Creating the directory let me create the app. Running that app gives me this traceback:
Traceback (most recent call last):
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 31, in
_run('app.py')
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 28, in _run
execfile(path, globals(), globals())
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/app.py", line 9, in
from pysqlite2 import dbapi2 as sqlite
ImportError: No module named pysqlite2
That brings the error reporting up to date, without trying any of the suggestions in the comments, yet. As I mentioned, the code itself works if I run django outside of the packaged application (from the command line, etc.). So I'm confident that my own imports are valid, etc.
Based on a hint from Tom (in the comments, he suggests that I install pysqlite2), I tried editing the app.py file created inside the application to import from sqlite3 instead of sqlite2. Editing the file directly didn't do it. Editing the copy already in my application changed the error message to:
Traceback (most recent call last):
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 31, in
_run('app.py')
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 28, in _run
execfile(path, globals(), globals())
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/app.py", line 10, in
from sqlite3 import dbapi2 as sqlite
ImportError: No module named sqlite3
Next I tried editing the version of app.py in /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/djangokit. After removing the application and rebuilding, I see the same error.
So I finally broke down and installed the pysqlte2 package Tom pointed out for me. The package seems to imply that it is for Python 2.4, and I'm running 2.5, but I installed it anyway.
The application Packaged with python 2.5 gave me "No module named pysqlite2" when I ran it. Repackaged using "python2.4 djangokit_setup.py py2app", I got the app to run but it does not seem to actually work. The console log shows this:
2007-06-23 15:07:28.403 Cook's Illustrated Index[14739] creating support folder /Users/dhellmann/Library/Application Support/DjangoKit/CooksIndex
2007-06-23 15:07:28.405 Cook's Illustrated Index[14739] installing default database
Starting web server on port 10557
Unhandled exception in thread started by
Traceback (most recent call last):
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/app.py", line 81, in startWebServer
handler = AdminMediaHandler(WSGIHandler(), path)
TypeError: __init__() takes exactly 2 arguments (3 given)
So, I am a lot closer but not quite where I would like to be. I don't really care whether I package under 2.4 or 2.5, so long as the result runs on my wife's laptop, which doesn't have any development packages installed.
Technorati Tags:
python, django
11 comments:
Sorry to hear that. Can you give me some detail on the error message? I'd like to be helpful..
Hi, Tom,
Here is the traceback from the log when I run the app I built against python 2.5. I should have included it in the original post.
Traceback (most recent call last):
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 31, in <module>
_run('app.py')
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/__boot__.py", line 28, in _run
execfile(path, globals(), globals())
File "/Users/dhellmann/Devel/personal/CooksIndex/trunk/dist/Cook's Illustrated Index.app/Contents/Resources/app.py", line 9, in <module>
from pysqlite2 import dbapi2 as sqlite
ImportError: No module named pysqlite2
I see the same error when I build with python2.4 explicitly. I wonder if the app is assuming that it can just run "python", which on my system is 2.5?
Doug
You may want to check if there's a copy of pysqlite2 in the application bundle at all.
The binary distribution for python2.5 on python.org is a universal binary and is set up to build universal binaries for extensions as well. Pysqlite is slightly problematic in that regard because it needs a C library as well.
BTW. Python2.5 includes an sqlite wrapper as well, which is "sqlite3" instead of "sqlite2".
Good point about the extension building. I'm happy to take this one step at a time. If I could get the app to run on the same machine where I build it, that would be a good first step. As I mentioned in my earlier comment, I suspect the problem might be due to the fact that by default "python" resolves to python2.5, but the application is trying to use pieces which should be coming from 2.4. Though that's just a guess and I have no real evidence of that.
Do you have XCode and Fink? I (think) I did the following.
1. Get xcode from ADC (http://developer.apple.com/) This includes a variety of useful tools.
2. Get fink (http://finkproject.org/) This will build things from source.
3. Get SQLite. I have a file called SQLite-2.8.16.dmg (don't know where I got it, didn't blog it well).
4. Get PySQLite. I have a file pysqlite-2.4.4-macosx2006-10-18.dmg. Again, not sure where I found it because I didn't take careful-enough notes.
I think that will build a working development environment. I haven't tried enough combinations to know if every step is truly necessary.
I have the django app working outside of the application. The only problem I'm having is with packaging it so I can copy it to another system without having to install everything from source again.
If things don't work out you can always post a message on the pythonmac-sig or pyobjc-dev mailinglist.
A small example that suffers from the same problem as your application would be helpful for debugging this issue as well.
cool idea. Glad I read your blog!
I'm pretty sure it's not a path to python issue - I've tried making my default python bin different and everything still works. It's very odd that you get the same error building with python 2.4, as that's the version I develop with..
Hmm, turns out that I have an explicitly installed pysqlite package for python on this machine, from http://pythonmac.org/packages/py24-fat/index.html so this may be the source of the 2.4 issues.
It would be nice if we worked under 2.5, though. I can replicate this one.
Now, line 9 of app.py - the import sqlite line - is there only to give py2app a hint that the application requires sqlite, so it gets packaged properly. Taking ronald's hint, I've tried importing the sqlite3 wrapper, followed by the pysqlite2 wrapper if that fails. This gets us a little further - now django explodes. :-)
Traceback (most recent call last):
File "/Users/tomi/External/djangokit/examples/DjangoWiki/dist/DjangoWiki.app/Contents/Resources/app.py", line 90, in startWebServer
run( '127.0.0.1', self.port, handler)
File "/Users/tomi/External/djangokit/examples/DjangoWiki/dist/DjangoWiki.app/Contents/Resources/Python/site-packages/django/core/servers/basehttp.py", line 642, in run
httpd.serve_forever()
File "SocketServer.pyc", line 201, in serve_forever
File "SocketServer.pyc", line 224, in handle_request
File "SocketServer.pyc", line 270, in handle_error
File "traceback.pyc", line 227, in print_exc
File "traceback.pyc", line 125, in print_exception
File "traceback.pyc", line 69, in print_tb
TypeError: fake_getline() takes exactly 2 arguments (3 given)
I'll keep poking - I'd like this to work under 2.5. But if you want a fix now, I'm fairly sure that installing the pysqlite2 package above should fix your 2.4 problems..
For anyone following the comment thread on this one, I updated the original post with more details and expected it to show up in the aggregator as having been updated. That didn't seem to happen.
After installing Python 2.5 I was having the same error:
ImportError: No module named pysqlite2
The I noticed Idle was still running Python 2.3. I uninstalled Python 2.3. Problem fixed.
Post a Comment