7
Setting up for Python development in Ubuntu
I’ve been working on a Python graphics library and trying to do some development in Ubuntu. It wasn’t going well, and most of the development took place on Windows XP. Much of the difficulty in Ubuntu was trying to make Python see the library as an installed library. To do that in Windows, I merely put the code in C:\Python26\lib\site-packages\balthasar, but trying to do the equivalent in Ubuntu with the dist-packages folder was a mess and, I gathered, a really bad idea altogether.
Fortunately, there is a simple way to edit the .bashrc file in Ubuntu to add a home directory folder to Python’s search path. Open up .bashrc in a text editor and add the following lines:
PYTHONPATH=$HOME/Python/lib EDITOR=gedit export PYTHONPATH EDITOR
$HOME, for me, is the folder /home/eric, so the Python folder is right in the main working directory. I’ve put the code for Balthasar in a subdirectory named lib. Now I can run examples that import balthasar from anywhere and they know where to look.
To verify that this worked, open the terminal and start the Python interpreter with python. Then type
>>> import sys >>> sys.path
The list that prints out shows all the places Python looks for packages when import is used. The second item for me is /home/eric/Python/lib, meaning this folder will work for putting work-in-progress libraries in.

