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?
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
PATH is the system path for executables, which is completely separate.
**You can write the above in
~/.bash_profile and the source it using
Not sure why Matthew's solution didn't work for me (could be that I'm using OSX10.8 or perhaps something to do with macports). But I added the following to the end of the file at
my directory is now on the pythonpath -
my-macbook:~ aidan$ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/path/to/dir', ...
and I can import modules from that directory.