Sunday, August 16, 2009

mac os x 10.5.8 virtualenv

So in trying to setup the macbook pro that I got for my new job I needed to setup a virtual environment for python. The way I understand it, mac os x 10.5 (leopard) comes packaged with python, which lives at /Library/Frameworks/Python.framework/Versions/4.3.0/. This might not be the default as I'm still trying to get my mac legs so-to-speak, and may be a result of installing the enthought python package but either way I wanted to setup a virtual python environment to that any programs I install do not interfere with the existing python setup. This is where the virtualenv python package comes in.

Here are the basic steps I had to go through to setup a usable virtual environment for python.
  1. Install enthought python
  2. Configure enthought python repositories: enthought defaults to using it's own repository which requires a username and password. So...
    1. open /Library/Frameworks/Python.framework/Version/4.3.0/lib/python2.5/site-packages/.enstallerrc
    2. edit the [repos] section to list only the following line: 1 = http://pypi.python.org/simple,index
    3. save the file
  3. Install virtualenv: run: /Library/Frameworks/Python.framework/Versions/4.3.0/bin/easy_install virtualenv
  4. Make the virtual environment: run: virtualenv
  5. Now for some reason mac os x doesn't like python accessing the screen so there is a separate pythonw that you have to run for graphical apps (like scipy). However, virtualenv does not create a pythonw in the /myPython/bin directory. So...
    1. download install_pythonw.py and pythonw.c from http://github.com/gldnspud/virtualenv-pythonw-osx/tree/master and put them in the same directory
    2. run: python install_pythonw.py /myPython
    3. now you should have a pythonw file in /myPython/bin
  6. at this point you should have a working virtual environment in /myPython but there are a few more useful steps
  7. install useful packages: /myPython/bin/easy_install ipython pudb winpdb
  8. fix ipython: open /myPython/bin/ipython and change the first line to read: #!/myPython/bin/pythonw
  9. create useful aliases, for the fish shell you can do this by typing the following:
    1. alias python /myPython/python
    2. alias ipython /myPython/ipython
    3. alias easy_install /myPython/easy_install
    4. funcsave python
    5. funcsave ipython
    6. funcsave easy_install
  10. add /myPython/bin to the path (again for fish shell)
    1. open ~/.config/fish/config.fish
    2. add the following line: set PATH $PATH /myPython/bin
  11. and (finally) you're done

No comments: