PYTHONPATH environment variable
Try appending to PYTHONPATH instead of overwriting it completely.
export PYTHONPATH=$PYTHONPATH:/home/dev/python-files
References:
According to the the Python documentation on PYTHONPATH
Augment the default search path for module files. [...]
The default search path is installation dependent, but generally begins with
prefix/lib/pythonversion
(seePYTHONHOME
above). It is always appended toPYTHONPATH
.
meaning that some values exist in PYTHONPATH
and the default search path is also only appended.
Additionally, this blog post (Archive.org link) also explains clearly why you need to append to PYTHONPATH
and not overwrite it. Scrolling down to the section - Special cases and examining the search path explains it clearly (unfortunately no relative URL to that link so you'll have to scroll). Although the user gives the examples on a mac they are very much relevant to any platform
You can also do as following:
export PYTHONPATH=$(pwd) **or** export PYTHONPATH=${PWD}
pwd is the present working directory.
PYTHONPATH
should point to where your Python packages and modules are, not where your checkouts are. In other words, if you do an ls "$PYTHONPATH"
you should see *.py
files (Python modules) and directories containing __init__.py
files (Python packages).
So, if you want to be able to import vgdl
, your PYTHONPATH
should look like this:
PYTHONPATH=/home/dev/python-files/py-vgdl
because the vgdl
package is inside py-vgdl
, not inside python-files
.
To add the other paths too, you can use :
to separate them:
PYTHONPATH="/home/dev/python-files/py-vgdl:/home/dev/python-files/something:$PYTHONPATH"
This will indeed work, however, for such cases, using PYTHONPATH
may be too complex. What I recommend is to use virtualenv
, which is made on purpose to simplify situations like yours. What you have to do is basically:
- Create an environment:
virtualenv env
- 'Activate' it:
source env/bin/activate
- Install your packages: this could be done either using
pip
or thesetup.py
script of your packages. - Enjoy.
I'm not giving much information because virtualenv is well-documented and if you need help with something, you'd better open a new question.