Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this in my ~/.profile:

export PYTHONPATH=/home/dev/python-files

In the python-files directory, I have a few projects cloned from git-hub (flask, curveship and py-vgdl).

Whenever I try to start up any of the examples in these projects, I get errors similar to the following:

$ python ~/python-files/py-vgdl/examples/gridphysics/ 
Traceback (most recent call last):
    File "/home/dev/python-files/py-vgdl/examples/gridphysics/", line 67, in <module>
        from vgdl.core import VGDLParser
ImportError: No module named vgdl.core

It seems to me that I shouldn't get this error because I have that PYTHONPATH environmental variable set up?

Running the python interactive interpreter:

>>> import os
>>> os.environ["PYTHONPATH"]
share|improve this question
Could you maybe accept one of the questions, if it was helpful? This will mark the question as resolved, which helps other users as well. – MERose Apr 20 at 8:17
up vote 7 down vote accepted

Try appending to PYTHONPATH instead of overwriting it completely.

export PYTHONPATH=$PYTHONPATH:/home/dev/python-files


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 (see PYTHONHOME above). It is always appended to PYTHONPATH.

meaning that some values exist in PYTHONPATH and the default search path is also only appended.

Additionally, this blog post ( 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

share|improve this answer
@Garrett Thanks :) Updated with link. – Nitin Venkatesh Jun 15 '15 at 15:44
+1 for the archive / stereoplex link. It answers so many questions it should be on the front page of the official Python docs! – Malik A. Rumi Jan 20 at 11:53

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 files (Python packages).

So, if you want to be able to import vgdl, your PYTHONPATH should look like this:


because the vgdl package is inside py-vgdl, not inside python-files.

To add the other paths too, you can use : to separate them:


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:

  1. Create an environment: virtualenv env
  2. 'Activate' it: source env/bin/activate
  3. Install your packages: this could be done either using pip or the script of your packages.
  4. 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.