Archive for the ‘python’ tag
Compile Vim in Snow Leopard
./configure –enable-pythoninterp –with-macsdk=10.6
Install PIL (Python Imaging Library) in Leopard
Installing modules when using pip, virtualenv and virtualenvwrapper is a breeze, but it took some time before I realized what was the easiest way to install PIL.
I do it this way:
pip -E PATH_TO_VIRTUALENV install http://dist.repoze.org/PIL-1.1.6.tar.gz
This installs a slightly repackaged version of PIL. The latest PIL version is 1.1.7, but as far as I know it’s not available in this form.
Chapter 7 in “Python Web Development with Django” – some notes
I am currently in the process of learning Django and have just finished chapter 7 in Python Web Development with Django. Here are some notes on how I got it working (except for the index page which still isn’t completely as expected) on an ubuntu hardy installation.
The photo gallery example assumes an apache2 + mod_python setup. I didn’t really find it straightforward to get this running from the description in the appendix, so here is how I got it to work (after installation of apache2 and mod_python, of course):
In /etc/apache2/sites-available/default, change lines:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
Then I did the changes in /etc/apache2/httpd.conf, but slightly different from the book by adding a PythonOption django.root (didn’t work for me with the setup in the book):
<Location "/gallery/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE gallery.settings
PythonOption django.root /gallery
PythonDebug On
PythonPath "['/path/to/django/root', '/home/user/django-stuff'] + sys.path"
</Location>
With an additional entry for media files:
<Location "/gallery/media">
SetHandler none
</Location>
Now, I created a directory /var/www/gallery and a /var/www/gallery/media like explained in “Preparing for File Uploads” and edited settings.py:
MEDIA_ROOT = '/var/www/gallery/media/'
MEDIA_URL = 'http://localhost/gallery/media/'
ADMIN_MEDIA_PREFIX = 'http://localhost/gallery/media/admin/'
Where admin is a symbolic link (/var/www/gallery/media/admin) to the admin media directory in the Django installation. The two last entries where not mentioned in the book, but they made it work…
With the settings described above and the PythonOption django.root in httpd.conf, I didn’t need the section about DRY URLs. And it worked – as opposed to the stuff in the book.
With all the configuration stuff in place I typed the code outlined in the chapter and to begin with I couldn’t see any photos, except for the thumb_url in items_list.html (typo: items_listing.html in the last paragraph page 175). I managed to get it working by changing some lines in items_detail.html and photos_detail.html though:
22 <img src="{{ photo.image.thumb_url }}" />
instead of
22 <img src="{{ photo.get_image_thumb_url }}" />
and
8 <img src="{{ object.image.url }}" />
instead of:
8 <img src="{{ object.get_image_url }}" />
The alternatives that worked seems more intuitive to me.
I also imported list_detail from django.views.generic in urls.py, but am not sure if this was needed. The photo gallery seems to work fine except for the thumbnails in index.html. I’ve noticed that the code in urls.py for that template is different from the others, using simple.direct_to_template, but I haven’t managed getting that part to work.
Thanks to this thread for getting mod_python up and running: Python and Apache2
Pydev in Eclipse on Mac
You will be asked to specify the where Python interpreter is located:
Please configure a Python or Jython interpreter in Window -> Preferences -> PyDev
before creating a new Pydev project
- Press Apple key and , (Preferences) and browse to the Python Interpreters submenu
- Choose New in the upper right and browse to /usr/bin/python
- Eclipse will then take care of the rest for you – ie. updating the $PYTHONPATH
NOTE: I use Eclipse 3.3.2 on Mac OS 10.5.2.
Reference: On Using Pydev on a Mac.