newbie trying understand sys.path

Fredrik Lundh fredrik at pythonware.com
Tue Feb 28 04:12:52 EST 2006


"MARK LEEDS" wrote:

> So, as it said in "Beginning Python", I went into my .bashrc file and did
>
> export PYTHONPATH=$PYTHONPATH:~/mytemp
>
> then, i typed pprint.pprint(sys.path) and it worked.
> it was in there !!!!!!!!!!!!!!!!!!!!!!!!
>
> but, now I want to take it out.
>
> i deleted the command from the .bashrc file and resourced it but it was still in there.

removing the PYTHONPATH variable from the bashrc script won't
remove the current value from the current environment.

> So, then I tried ( inside a python program )
>
> sys.path = sys.path[1:]
>
> and it works inside the program so that sys.path changed while the program
> was running.
>  but, then i checked it again, by taking out the above command
> and typing pprint.pprint(sys.path) and it was still there ?
>
> Basically, my question is : Is there a permanent way of taking things out of
> sys.path that you put in sort of by accident or for experimentation ?

you can log out and log in again.

or you can use export to set PYTHONPATH to whatever value you
want it to have.

or you can use "unset PYTHONPATH" to remove it from the environment:

    $ echo $PYTHONPATH

    $ export PYTHONPATH=spam
    $ echo $PYTHONPATH
    spam
    $ python -c "import sys; print sys.path[:2]"
    ['', '/home/fredrik/spam']
    $ unset PYTHONPATH
    $ echo $PYTHONPATH

    $ python -c "import sys; print sys.path[:2]"
    ['', '/usr/local/lib/python2.5']

</F>






More information about the Python-list mailing list