2

I want to clean up my PYTHONPATH.

I know I appended it in /home/me/.profile, like so:

PYTHONPATH=/home/hoff/code/someproject/pythonmods:$PYTHONPATH
PYTHONPATH=/home/hoff/code/google_appengine/google/appengine/tools:$PYTHONPATH
export PYTHONPATH

But there must be other places I have appended the PYTHONPATH, when I go into a python interpreter and and look at sys.path, there are all sorts of additional directories.

Where might I have specified them, i.e. what are all the possible place where one can append the PYTHONPATH (on linux/ubuntu)?

3 Answers 3

3

sys.path and PYTHONPATH are not the same thing; the former subsumes the latter. To find out the value of PYTHONPATH, do echo $PYTHONPATH in the shell.

The files /usr/{local/,}lib/pythonX.Y/dist-packages/site.py will update sys.path so you can import packages installed with apt-get, easy_install and pip. Uninstalling these packages will trim down your sys.path (though not your PYTHONPATH).

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

Comments

1

As said before...It could be set almost anywhere. A few places that I would look (assuming your login shell is the typical bash...)

.bashrc
/etc/profile
Anything in /etc/profile.d/  (typically loaded from /etc/profile)
~/.bash_profile
~/.bash_login

from man bash

  When bash is invoked as an interactive login shell, or as
  a non-interactive shell with the --login option,  it  first
  reads  and  executes commands from the file /etc/profile, 
  if that file exists.  After reading that file, it looks for
  ~/.bash_profile, ~/.bash_login, and ~/.profile

and

   When an interactive shell that is not a login shell is started,
   bash reads and executes commands from  ~/.bashrc,  if that
   file exists.

1 Comment

.bashrc was the place I was looking for, had a bunch of "export pythonpath" in there...
1

Anywhere where an environment variable can be set.

Processes inherit their parent's environment, so you can modify it at any stage, be it the shell config files, in the shell's commandline, any intermediary script you call, the python script (with sys.path) or any library it use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.