Getting PIL Installed on OS X 10.6 Snow Leopard with JPEG Support

Now that I’m working on run my app with a remote MySQL setup, I’m kind of doing a system reset of sorts at the same time.

I had about 25 virtualenvs in various states of biochemical degradation, so I just flippin’ deleted’em.

All gone. Bye bye.

I’m going to need PIL in all of my virtualenvs, so I’m going to just install it into my current Python (2.6.4, installed from the binary at python.org). Of course, that probably won’t work since not everything in `site-packages` seems to get copied/linked over, but I’ll burn that bridge when I get to it.

Getting and Building PIL

I first downloaded the PIL 1.1.6 source kit, ran the usual `sudo python setup.py install` and got the message at the end about what types of files it would be able to process. JPEG was flagged as a no-go. Not being able to process JPEG files would make PIL pretty flippin’ useless.

Went and got the jpeg library, unarchived it, and followed the instructions at Proteus Technologies, to compile with `–enable-static` which PIL seems to need, at least according to that site.

$ tar zxvf jpegsrc.v7.tar.gz
$ cd jpeg-7
$ ./configure --enable-shared --enable-static
$ make
$ sudo make install

God, I love things that compile without any warnings or errors.

Went back to PIL and re-ran the install and it went like this:

)# sudo python setup.py install
running install
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version       1.1.6
platform      darwin 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
              [GCC 4.0.1 (Apple Inc. build 5493)]
--------------------------------------------------------------------
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--------------------------------------------------------------------
To check the build, run the selftest.py script.
running build_scripts
running install_lib
running install_scripts
changing mode of /Library/Frameworks/Python.framework/Versions/2.6/bin/pilconvert.py to 755
changing mode of /Library/Frameworks/Python.framework/Versions/2.6/bin/pildriver.py to 755
changing mode of /Library/Frameworks/Python.framework/Versions/2.6/bin/pilfile.py to 755
changing mode of /Library/Frameworks/Python.framework/Versions/2.6/bin/pilfont.py to 755
changing mode of /Library/Frameworks/Python.framework/Versions/2.6/bin/pilprint.py to 755
running install_egg_info
Removing /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/PIL-1.1.6-py2.6.egg-info
Writing /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/PIL-1.1.6-py2.6.egg-info
creating /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL.pth

Yay!

Enable Remote Access to MySQL

I haven’t set MySQL up in years; it’s always on the server, and I guess we never try to access it from outside.

So… I had completely forgotten about allowing access. Fortunately, it only took a few quick Googles before I had the answer and, even though it’s in a million other places, I’m going to add it here since I want to be able to use this blog as my reference.

Edit, on Ubuntu, with:

	$ sudo vim /etc/mysql/my.cnf

And make it look like this:

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 127.0.0.1
bind-address = you.re.ip.add
# skip-networking

In 5.1.x it seems that `skip-networking` has been dropped as the default and `bind-address` is 127.0.0.1 by default. I just left that in place and added my IP address. I’m not sure if that’s right, but it works.

I found the full reference here. I really like that ‘nixCraft’ site; I seem to end up there a lot.

Stupid MySQL Python with Stupid 64 bit MySQL on Stupid 64 bit Snow Leopard (Part 2)

So…

Now that it’s morning, I went back to square 1 and killed the build directory again.

Set the architecture flags as before, and rebuilt.

Then, I ran:

	# sudo python setup.py install

And noticed that it is building the library again, a completely different way before installing!

What the Heck is Going On?!

Whereas before, I had one directory and one temp directory in my build subdirectory, I now have TWO libraries built.

One right, one not.

)# ll build
total 0
drwxr-xr-x   7 ssteiner  staff  238 Dec 31 09:26 .
drwxr-xr-x  29 ssteiner  staff  986 Dec 31 09:25 ..
drwxr-xr-x   2 root      staff   68 Dec 31 09:26 bdist.macosx-10.3-fat
drwxr-xr-x   5 root      staff  170 Dec 31 09:26 lib.macosx-10.3-fat-2.6
drwxr-xr-x   5 ssteiner  staff  170 Dec 31 09:25 lib.macosx-10.3-x86_64-2.6
drwxr-xr-x   3 root      staff  102 Dec 31 09:26 temp.macosx-10.3-fat-2.6
drwxr-xr-x   3 ssteiner  staff  102 Dec 31 09:25 temp.macosx-10.3-x86_64-2.6

I didn’t tell it to build a fat one, I told it to build the x86_64 one. It decided to build the other one when I went to install the one I had built.

Now we’re getting somewhere…

Because, like everyone else, I was building as my regular user, but installing with `sudo`, the `sudo` shell didn’t have the architecture set and, so, built a 32 bit OS X 10.3 compatible version, then installed that.

The Solution

By using a virtualenv, you don’t have to switch users to get it to install and, therefore, you don’t get a second build.

Jeez, that was stupid…

Stupid MySQL Python with Stupid 64 bit MySQL on Stupid 64 bit Snow Leopard

So…

I’ve decided to go with MySQL for my latest product for a variety of reasons.

To build MySQL support for Python, you have to have the MySQL headers and such available.

Even though I installed from the MySQL supported binary for OS X 10.6, the MySQL-python installer couldn’t find the support files.

To get it to work, I had to edit `site.cfg` in the `MySQL-python-1.2.3c1` directory to uncomment out line 13 and edit it to read:

mysql_config = /usr/local/mysql/bin/mysql_config

The comment in the code says, above that:

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.

Well, isn’t that special…

Then, to add insult to stupidity:

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 13, in 
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql)

I found some instructions that suggested trashing the build directory, then executing the following (I broke it into separate lines):

# export ARCHFLAGS="-arch x86_64"
# python setup.py build
# sudo python setup.py install

This, however, gave me the same error on import.

So, I trashed `build`, `dist`, and `*.egg-info` and tried again.

Same shit.

So, I dug a little deeper. Of course, there’s always the suggestion that one build MySQL from source, but that just seems melodramatic.

It’s not complaining about MySQL, it’s complaining about the module not defining an init function.

I hunted down this thread that seems to be right up to yesterday so obviously I’m not the only one arguing with this:

http://cd34.com/blog/programming/python/mysql-python-and-snow-leopard/

So far, the solutions all seem to say to run Python in 32 bit mode but that just seems idiotic. I’ve got 64 bit everything and this library just doesn’t seem to have correct build instructions. I’m not going to start crippling my system in the hopes of making it limp along; that’s just stupid.

Of course, it’s after 1am and so am I right now so I think I’ll stop…for now.

Allowing Clean URLs in Drupal

So… I had this nice fresh Drupal in my new PostgreSQL installed Apache.

Clean URLs were disabled by default and couldn’t be enabled.

To enable them, I first upgraded to the latest Drupal and made sure to copy the .htaccess file that PostgreSQL forgot in insert.

Then, in the that specified the …/www directory, I changed AllowOverride to All from None and clean URLS were magically allowed.

Between the .htaccess specifically adding rewrite rules and httpd.conf allowing them, we’re all set.

Yay.

Getting PostgreSQL Running on OS X 10.6

So…

I’m getting ready to deploy some new web applications and, normally, I’d just go ahead and use the installed mySQL server on our CentOS based servers and that would be that.

Except that we’re not going to be running on one of those…

So I figured I’d take some time to just install PostgreSQL.

That turned out to be pretty darn slick.

Get the binary installer from here, run the installer, and voilĂ !

After installation, it brings you to an installer that will let you install a few handy add-ons like a full Apache 2.2.x, Drupal, ODBC and JDBC drivers, some performance tuning tools, replication, and such.

I used the installer to install Apache 2.2.14 (latest stable 2.2 branch), Drupal, phpPgAdmin 4.2.2, and the JDBC driver. Damn handy, that.

One small wrinkle that I’ve not quite worked out but have worked around.

When you install phpPgAdmin, the postgres (root) user is not allowed to log in so you have to go into the config file way the heck down in:

/Library/PostgreSQL/EnterpriseDB-ApachePhp/apache/www/phpPgAdmin/conf

and tweak the:

 $conf['extra_login_security'] = false; #  true;

setting to false from true.

Then you can login with the postgres user. To add users, just go into the pgsql command, using the postgres user.

There are some more fun things to do at the Apple link for PostgreSQL which I’ll get to later.

To get the Python driver recommended for use with Django, I went to the ugly site pointed to by the Django documentation. Not sure what’s up with that.

Anyway, that’s what it took, I’ll write more after I do a bit more poking around…

Getting Validator S.A.C. Running Under Snow Leopard

I’m using the Validator quit a lot lately, for reasons which will become apparent soon enough.

In order to run the stand-alone validator on an OS X machine, just download from the link above, and install the app normally.

Open it up, and you’ve got a validator right there on your computer that works much faster than the online one, and it can also validate local files (as long as they’re straight HTML).

The other cool thing you can do, is set it up to respond to local requests via the Web Service API.

To do this, you just have to leverage the Apache already running on your machine by following the instructions right on the home page. The instructions for 10.5 worked in 10.6 for me:

 # cd /Applications/Validator-SAC.app/Contents/Resources
 # sudo cp validator/httpd/conf/validator-SAC-10.5.conf /etc/apache2/other
 # sudo apachectl graceful

After that, a quick test using curl proves that the install is working:

 # curl http://localhost/w3c-validator

And out comes the HTML for the validator homepage (which I’ve given up trying to get MarsEdit to allow me to show any of in this document).

At any rate, you can now use the validator right on your machine without hitting the net except for getting the page to validate.

Cool!

BitBucket, Mercurial, and Public Keys

I’ve been using BitBucket and Mercurial quite a bit lately and have always use passwords to log in for a `push` up to the server.

That’s now gotten sufficiently annoying that I just found the documentation.

Since I already had a working public key, and already had it installed at BitBucket, I just picked up at “Enabling Compression” in the docs.

I already had a shell script for doing a push, so I just modified it to use the “hg” user, instead of my user name, as per the doc.

What I missed was the instructions to change the protocol from https to ssh.

So, I started with:

# Just a quick dev push to the current private repo
hg push https://ssteiner@bitbucket.org/ssteiner/reponame

And ended up with:

# Just a quick dev push to the current private repo
hg push ssh://hg@bitbucket.org/ssteiner/reponame

which just worked.

Yay!

JavaScript Command Line Shell OS X

So…

I was writing a whole bunch of JavaScript recently and was getting incredibly tired of having to refresh the browser to see if things were working.

Yes, I have FireBug and such but what I really want is a command-line JavaScript interpreter like my iPython.

To make a long story short, none of the instructions I found for building SpiderMonkey worked on OS X and I couldn’t find a binary so I went to plan B: Rhino.

Download and unzip. What you’ll get is a directory named `rhino1_7R2`.

So, once you have that, just go get jLine. It’s a single .jar file, stick that into your `rhino1_7R2` directory. Mine is named `jline-0_9_5.jar`.

Make sure you’re in your `rhino1_7R2` directory where you should see something like this if you do an `ls`:

(~/rhino1_7R2)# ls *.jar
-rw-r--r--@ 1 ssteiner  staff    46424 Dec  6 09:00 jline-0_9_5.jar
-rw-r--r--  1 ssteiner  staff  1164702 Mar 22  2009 js-14.jar
-rw-r--r--  1 ssteiner  staff   871260 Mar 22  2009 js.jar

then type the oh-so-completely-obvious command:

(~/rhino1_7R2)# java -classpath js.jar:jline-0_9_5.jar jline.ConsoleRunner
 org.mozilla.javascript.tools.shell.Main

You’ll see the `js>` prompt and there you are; a full JavaScript command line to try things out in.

I got some great help from this article when I was first starting this exploration and he goes into mixing Java and JavaScript code a little bit which is of no interest to me, at this point.

Sure is nice to have a command line to whack around to try out regular expressions and such though…

VirtualBox on OS X 10.6 With Ubuntu 9.10

So…I wanted to run VirtualBox with Ubuntu 9.10 as my testbed for some new stuff. I had been mostly happy using Parallels version 4.0, mostly.

To make a long story short, Ubuntu 9.10 crashed Parallels 4.x and I wasn’t really interested in upgrading Parallels again since their Ubuntu support has always given me troubles.

So I downloaded Sun’s VirtualBox.

To make a long story short, forget all the dhcpserver stuff related to Host-Only ethernet ports. I got it to work; once. Then, for hours, tried every combination I could find on the InterWebs and got nowhere.

How to Actually Make It Work

Make the second port (from the GUI) a Host-Only adapter, take defaults for everything else.

Go to your Mac command line and type:

# VBoxManage list hostonlyifs

Note the IP address of the 192.168.XXX.1 adapter — that’s your gateway and gives the 3 octet for the addresses below. Mine was 56 so I had 192.168.56.1 for my gateway.

Then go sudo vim /etc/network/interfaces and add this to the end:

auto eth1
iface eth1 inet static
address 192.168.XXX.10
netmask 255.255.255.0
gateway 192.168.XXX.1

Restart the networking with:

# sudo /etc/init.d/networking restart
# ifconfig

You should see your second port all set up, should be able to ping it from your Mac, etc.

What a pain! Hopefully this saved you some; it took hours to figure this out.

Let me know if this helped; I’d love to hear.

S