Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

permanently remove directory from python path

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?

like image 490
Ryan Saxe Avatar asked Oct 08 '13 19:10

Ryan Saxe


People also ask

How do you clear a 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.

How to remove or delete an empty directory in Python?

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.

How to remove/delete a file path in Python?

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.

How to delete a directory and all files from 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.

How to delete all files in the/tmp directory in Python?

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:


2 Answers

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.

like image 71
Zack Su Avatar answered Sep 18 '22 10:09

Zack Su


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.

like image 38
Chandan Kumar Avatar answered Sep 17 '22 10:09

Chandan Kumar