0

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.

1

1 Answer 1

2

Yo need to export PYTHONPATH in your .bashrc:

export PYTHONPATH

Exporting enables children processes to inherit the environment variable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.