tags:

views:

97

answers:

2

I know there are multiple solutions online, but some are for windows, some are environmental variable, etc..

What is the best way?

+5  A: 

Find your site-packages directory and create a new file called myproj.pth

Inside that file, put each directory you want to add, one per line like so:

/home/myuser/svn-repos/myproject
/home/myuser/svn-repos/SomeOtherProject

Python loads *.pth every time it runs, and imports all paths in each of those files.

In Ubuntu, that directory can often be found at /usr/local/lib/python2.6/dist-packages/

Paul McMillan
There is some documentation for this at http://docs.python.org/library/site.html
jleedev
What if you install python3.1? then the path(es) won't be imported
hasen j
That is by design. Python 3k is substantially different than python 2.x, and so you need to re-do this sort of configuration. If you're already using Py3k, put your .pth in the Py3k site-packages directory.
Paul McMillan
Well, what if you were on 2.5 and then you moved to 2.6? My point is, you'll have to copy this file around, where as if you define PYTHONPATH in `~/.bashrc` you won't have such an issue
hasen j
If you define PYTHONPATH in your ~/.bashrc, you have to copy that file around for each user of your system. Ever have anyone else do work on the same machine? Ever do work as www-admin?
Paul McMillan
Then put it in /usr/local/lib/site-python. That'll stay constant from install to install. I recommended the specific version site path because it keeps python from barfing when you change versions and your code is incompatible.
Paul McMillan
+1  A: 

I personally just define PYTHONPATH in ~/.bashrc, as for what's the "best" approach? I think that's hard to answer (or rather, there's no correct answer). It depends.

hasen j
You might want to take out the waffling and just say `PYTHONPATH` so we can vote that up.
S.Lott
Well, the "waffling" is part of my answer. I mean, obviously the dude already knows about `PYTHONPATH`, so just mentioning it alone doesn't add any value.
hasen j