pip: Uninstalling package from specific directory

I installed package into specific local directory using pip install -t <dir>.

Now I want to uninstall it, but I cannot find a way to uninstall from that specific directory. For uninstall there is no valid option -t | –target, which exists for install command.

Best answer

Remove them manually. pip does not keep hidden directories of installed packages and scans directories such as /usr/local/lib/python2.7/dist-packages directly to determine what is installed.

So, if you installed something using -t just go to the directory you specified and delete all traces, including any metadata files. For example,

$ mkdir localpips
$ pip install -t localpips docopt
Downloading/unpacking docopt
  Downloading docopt-0.6.2.tar.gz
  Running setup.py (path:/tmp/pip_build_garyw/docopt/setup.py) egg_info for package docopt

Installing collected packages: docopt
  Running setup.py install for docopt

Successfully installed docopt
Cleaning up...
$ cd localpips
$ ls -l
total 48
drwxr-xr-x 2 garyw garyw  4096 Jul  6 17:27 docopt-0.6.2.egg-info
-rw-r--r-- 1 garyw garyw 19946 Jul  6 17:27 docopt.py
-rw-r--r-- 1 garyw garyw 23326 Jul  6 17:27 docopt.pyc
$ 

To uninstall it, just go into localpips and delete the files and directories that were created.

I know, it’s not that elegant, and sometimes you have no idea what may be related to what if you didn’t observe the install carefully, but that’s the way it is.