Home > Linux, Python, Ubuntu > Append to PYTHONPATH in Ubuntu

Append to PYTHONPATH in Ubuntu

Not sure how other distros have this setup, but I know this works with Ubuntu…

First off, to view your PYTHONPATH. Load the python shell, by just running “python” from your favorite prompt. Then the following.


>>> import sys
>>> for line in sys.path: print line

Modifying it is as simple as adding a path file (such as “myproject.pth”) to this folder:

/usr/local/lib/pythonx.y/site-packages

Then within the file “myproject.pth” put the path to the folder of interest.

Important asside:
Although this is useful to know, the reason I ended up figuring this out was to add the path of my project so that my own project could access a certain folder within the project. What I really missed was just adding an __init__.py within the folder I added to my project, which is why I couldn’t treat the folder as a module… Arg!

Categories: Linux, Python, Ubuntu Tags:
  1. January 24th, 2009 at 21:27 | #1

    For some reason I’m having a little tif with PYTHONPATH in .bashrc myself at the moment :(

  2. Igor Ganapoolsky
    January 20th, 2010 at 17:35 | #2

    michael: good advise, and I didn’t even know about the $PYTHONPATH. However, even after making the changes I still get an error “Import Error: No module named ext” – where ext is a folder under which I created _init_.py.

  1. No trackbacks yet.