Karnivaurus
Karnivaurus

Reputation: 24111

Importing a module from PYTHONPATH

I am trying to import a python module from a particular directory on my system, but cannot get this working. Here is what I have tried:

1) Created a test file at /home/karnivaurus/foo.py which contains just the line print('Hello world')

2) Edited my .bashrc file to contain the line PYTHONPATH="$PYTHONPATH:$HOME"

3) Tested this by opening a new terminal and running echo $PYTHONPATH, which prints out ":/home/karnivaurus"

4) Started a python interpreter in the terminal by running python

5) Importing my test file by running import foo

However, this just returns the following error:

ImportError: No module named foo

What am I doing wrong?


Edit:

I have tried printing sys.path from the interpreter, and it prints out a number of directories, but does not print out /home/karnivaurus. So it seems that sys.path is not being updated by PYTHONPATH.

Upvotes: 0

Views: 108

Answers (1)

user803422
user803422

Reputation: 2814

Yo need to export PYTHONPATH in your .bashrc:

export PYTHONPATH

Exporting enables children processes to inherit the environment variable.

Upvotes: 2

Related Questions