OS X & MacPorts, installing MySQL driver, virtualenv, virtualenvwrapper
I’d been doing nearly all work of late using my Core-I7 Dell Studio 17 laptop running Ubuntu 10.04. It’s a powerful machine, but the screen even at 17 inches seems to not cut it. I have an iMac with a second Samsung monitor, and notice this setup is easier on the eyes and also makes separating tasks among screens possible. Add to that issue the fact I’m hogging both the iMac and laptop (using one keyboard + mouse via Synergy) and lately my wife bugs me a lot to use one of the two computers; hey I don’t blame her! I decided to stop hogging em both and get the iMac back up and running for work. It’s slow, a Core2 Duo, but again I’ve learned monitors take precedence for me over raw computing power.
So it’d been awhile and I wasn’t sure what to expect, environment wise. I took a look at the Python setup and found it in disarray. I had numerous versions of python installed, via MacPorts and otherwise, as well as multiple versions of common tools. I started my quest for cleanliness by removing all of the the unused/un-needed Python versions. I had MacPort’s up to date 2.6.6 (vs Apples 2.6.1) installed already so I just removed the 2.4 and 2.5 versions (why where these installed?).
The next major issue was that virtualenv (and virtualenvwrapper) did not function proper with the 2.6.6 Python version, they pointed to the Apple version. I could have simply used the easy_install MacPorts had already added for me to install virtualenv(+wrapper) but instead I used the MacPorts for them. This seems kinda odd but I wanted to give it a try. I also installed the MySQL driver via MacPorts at this time. Here are the commands:
sudo port install py26-virtualenv sudo port install py26-virtualenvwrapper sudo port install py26-mysqldb
Note read the errors carefully if you get any. I received errors due to old/other versions of easy_install, ones not managed by ports. The fix was just deleting those, and then letting MacPorts install it’s managed version of easy_install.
I created a folder for storing the virtualenvs @ ~/Documents/development/virtualenvs. With the above installs complete I needed to add some stuff to ~/.profile so that wrapper works. The following are the lines I added to .profile:
export PIP_RESPECT_VIRTUALENV=true export WORKON_HOME=~/Documents/development/virtualenvs source /opt/local/bin/virtualenvwrapper_bashrc-2.6
You’ll have to change the value of WORKON_HOME to fit where you put your folder. The line “source …” is important because it sets up the wrapper commands when you open a shell.
Test everything out by typing in “mkvirtualenv test” then if that works open a Python interpreter and type “import MySQLdb” which if it doesn’t fail you have installed the driver successfully!