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?
remove() method in Python is used to remove or delete a file path. This method can not remove or delete a directory. If the specified path is a directory then OSError will be raised by the method.
Note: To know more about os.remove () click here. os.rmdir () method in Python is used to remove or delete a empty directory. OSError will be raised if the specified path is not an empty directory. path: A path-like object representing a file path.
The OS module in Python provides methods to interact with the Operating System in Python. The remove () method in this module is used to remove/delete a file path. Import the shutil module and pass directory path to shutil.rmtree ('path') function to delete a directory and all files contained in it.
Use the rmtree () method of a shutil module to delete a directory and all files from it. The Python shutil module helps perform high-level operations in a file or collection of files like copying or removing content. path – The directory to delete. The symbolic links to a directory are not acceptable.
The following example code deletes all .txt files in the /tmp directory: In Python you can use os.rmdir () and pathlib.Path.rmdir () to delete an empty directory and shutil.rmtree () to delete a non-empty directory. The following example shows how to remove an empty directory:
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.
This is for windows users. so if you have any custom module installed using
pip install --user -e <package>
.
Then the module path can be found in .pth file. Generally it is named as easy-install.pth
and can be found in site-packages directory. Try removing the entries from this file and then check the sys.path
again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With