I recently added some things to my python path that I don't want there using:
export PYTHONPATH=$PYTHONPATH:/my/path
You can use sys.path.remove
to remove something in the path, but it's not 100% permanent like the way I added it with the command line statement above.
what can I do to permanently remove directories from the python path?
Your persistent Python path is usually set via a shell startup file like ~/.bashrc.
Modifying the PYTHONPATH variable within a shell will only change its value for the current instance of your shell and its childen when using 'export' but is by no mean intended to change its value permanently.
Use the following command to find where to modify your path:
grep -l PYTHONPATH ~/.*
If it's hardcoded in a startup file edit its value there, spawn a new shell and voila!
Alternatively a path may be added to Python's path via a .pth file in its existing path that refers to another location.
Should this be the case erasing it permanently from Python's path should be as simple as erasing this file.
First, from terminal grab everything in your path by using
env | grep PYTHONPATH
Then, export your path and manually remove anything you no longer need:
export PYTHONPATH=[this is where you paste the corrected paths, no square brackets needed]
If you restart your session and you haven't modified anything in .bashrc, you can simply close and reopen your session.
If you simply delete the line "export PYTHONPATH=..." in .bashrc and do "source .bashrc", those directories would still be in sys.path.
Unlike "export PATH" in .bashrc, it seems that when you export some directories into PYTHONPATH, they are dump into some file which python can always check.
So, what you need to do is "export PYTHONPATH=" (export empty string) and do "source .bashrc". This will clean up everything you have export into PYTHONPATH before in .bashrc.
If the line you mention is in your .bashrc, it should be safe to simply delete it.
Exactly as it stands, what the line says is "add /my/path to PYTHONPATH", so it should be fairly safe even if there are others around your .bashrc.