permanently remove directory from python path

不问归期 提交于 2019-12-04 02:02:37

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!