Everything works as intended on my machine 🙂
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/sergey')
>>> sys.path
['', ..., '/home/sergey']
>>> sys.path.remove('/home/sergey')
>>> sys.path
['', ...]
>>>
What exactly have you tried?
Regarding your understanding of things – I’m afraid there are some mis-understandings:
-
sys.pathis a list of directories which contain Python modules, not system libraries. So, simplifying, when you have something likeimport blahin your script, Python interpreter checks those directories one by one to check if there is a file calledblah.py(or a subdirectory namedblahwith__init__.pyfile inside) -
Current directory is where the script is located, not where Python interpreter is. So if you have
foo.pyandbar.pyin a directory, you can useimport barinfoo.pyand the module will be found because it’s in the same directory. -
$PYTHONPATH is an environment variable which is getting appended to
sys.pathon interpreter startup. So, again, it is related to module search path and has nothing to do with starting Python from command line. -
Correct, you can modify
sys.pathat runtime – either when running a python script on in IDLE
See sys.path and site for more details.