views:

301

answers:

1

I thought

import sys
sys.path.append("/home/me/mydir")

is appending a dir to my pythonpath

if I print sys.path my dir is in there.

Then I open a new command and it is not there anymore.

But somehow Python cant import modules I saved in that dir.

What Am I doing wrong?

I read .profile or .bash_profile will do the trick.

Do I have to add:

PATH="/Me//Documents/mydir:$PYTHONPATH"
export PATH

To make it work?

+1  A: 

Modifications to sys.path only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH environment variable:

PYTHONPATH="/Me/Documents/mydir:$PYTHONPATH"
export PYTHONPATH

Note that PATH is the system path for executables, which is completely separate.

Matthew Flaschen
Thanks a lot (forgot that). WHERE do I put that? in .profile in .bash_profile? Before Macpython?:# Setting PATH for MacPython 2.6# The orginal version is saved in .bash_profile.pysavePATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"export PATHOr after that?Does order matter?
MacPython
`.bash_profile`. If you already have a `.bash_profile`, I believe bash ignores `.profile`. Order doesn't matter here, because they're two different environment variables.
Matthew Flaschen
@Felix, note that the MacPython code he has deals with `PATH` (system path), a separate variable.
Matthew Flaschen
@Matthew Flaschen: You are right, thanks.
Felix Kling
So I did add PYTHONPATH "path:$PYTHONPATH" export PYTHONPATH and AFTER I restarted my computer it worked. Big Thanks to Matthew and Felix!!
MacPython