6

I am running ubuntu, and I don't have a .bash_profile.

So my question is, where exactly is my python path set then?

How can I see what the current python path is, doing:

$PYTHON_PATH

doesn't return anything?

The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156
Blankman
  • 259,732
  • 324
  • 769
  • 1,199

4 Answers4

5

It's set by the site module, and the interpreter executable itself. sys.path contains the current value.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
4

You can see your python path in python like so:

>> import sys
>> print sys.path
Alex Bliskovsky
  • 5,973
  • 7
  • 32
  • 41
  • 1
    sys.path lists a long list of paths. However, if I exit the python shell and type `echo $PYTHONPATH`, I get nothing. What I am doing wrong? – Shailen Aug 24 '13 at 15:01
  • @shailenTJ If you are using virtualenv (add2virtualenv) PYTHONPATH will show nothing for you (empty return). All paths added by virtualenv (add2virtualenv command) are saved inside /path/to/your/site-packages/_virtualenv_path_extensions.pth – Mauricio Abreu Apr 22 '14 at 21:39
1

you can create a .bash_profile with your favorite editor, and put into it:

export PYTHONPATH=$HOME/lib/python

or whatever, that's one example.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
0

echo $PYTHONPATH /etc/profile and /etc/bashrc are the global setting files bash scans before looking in your home directory at start up. It's also safe to create a .bash_profile if one doesn't exist.

Normally PYTHONPATH is empty anyways.

Mike Ramirez
  • 10,750
  • 3
  • 26
  • 20
  • Normally PYTHONPATH is not set and it's different from empty: empty PYTHONPATH is the same as setting it to CWD. – Alex B Jun 22 '12 at 02:18