pip uninstall pip will work
pip uninstall pip will work
That way you haven't installed pip, you installed just the easy_install i.e. setuptools.
First you should remove all the packages you installed with easy_install using (see uninstall):
Copyeasy_install -m PackageName
This includes pip if you installed it using easy_install pip.
After this you remove the setuptools following the instructions from here:
If setuptools package is found in your global site-packages directory, you may safely remove the following file/directory:
Copysetuptools-*.egg
If setuptools is installed in some other location such as the user site directory (eg: ~/.local, ~/Library/Python or %APPDATA%), then you may safely remove the following files:
Copypkg_resources.py
easy_install.py
setuptools/
setuptools-*.egg-info/
python - How to uninstall a package installed with pip install --user - Stack Overflow
How do you remove pip from a pc if you installed by "get-pip.py"
How to uninstall all Python packages installed with pip?
python - How do I remove all packages installed by pip? - Stack Overflow
Videos
Ubuntu Oneiric (and I expect newer versions too) install pip packages to /usr/local/lib/python2.7/dist-packages, and apt packages to /usr/lib/python2.7/dist-packages. So just check the former directory and sudo pip uninstall every package you find there.
Pip currently ignores uninstall commands that try to uninstall something owned by the OS. It doesn't error out, like it does with a missing package. So, now you can uninstall with the following process:
pip freeze > dump.txt
Edit the dumped file to remove any -e "editable install" lines, everything after the == sign (%s;==.*;;g in vim), swap the new lines for spaces (%s;\n; ;g in vim). Then you can uninstall all un-owned packages with
cat dump.txt | xargs sudo pip uninstall -y
I had to do this procedure twice, because a few packages were installed in ~/.local/lib too.
A one-liner to accomplish this:
pip freeze | grep -vP '^(?:#|-e\s)' | sed 's;==.*;;g' | xargs -r sudo pip uninstall -y
Having tested this using Python 3.5 and pip 7.1.2 on Linux, the situation appears to be this:
pip install --user somepackageinstalls to$HOME/.local, and uninstalling it does work usingpip uninstall somepackage.This is true whether or not
somepackageis also installed system-wide at the same time.If the package is installed at both places, only the local one will be uninstalled. To uninstall the package system-wide using
pip, first uninstall it locally, then run the same uninstall command again, withrootprivileges.In addition to the predefined user install directory,
pip install --target somedir somepackagewill install the package intosomedir. There is no way to uninstall a package from such a place usingpip. (But there is a somewhat old unmerged pull request on Github that implementspip uninstall --target.)Since the only places
pipwill ever uninstall from are system-wide and predefined user-local, you need to runpip uninstallas the respective user to uninstall from a given user's local install directory.
Be careful though, for those who using pip install --user some_pkg inside a virtual environment.
Copy$ path/to/python -m venv ~/my_py_venv
$ source ~/my_py_venv/bin/activate
(my_py_venv) $ pip install --user some_pkg
(my_py_venv) $ pip uninstall some_pkg
WARNING: Skipping some_pkg as it is not installed.
(my_py_venv) $ pip list
# Even `pip list` will not properly list the `some_pkg` in this case
In this case, you have to deactivate the current virtual environment, then use the corresponding python/pip executable to list or uninstall the user site packages:
Copy(my_py_venv) $ deactivate
$ path/to/python -m pip list
$ path/to/python -m pip uninstall some_pkg
Note that this issue was reported few years ago. And it seems that the current conclusion is: --user is not valid inside a virtual env's pip, since a user location doesn't really make sense for a virtual environment.
I have recently installed Python on my new computer. Although my intension was to make a virtual environment for every project, I somehow forgot to activate one before installing a bunch of packages. Now, every time I create a new virtual environment, all these packages are already there.
I have tried to use --no-site-packages, but later found out that this flag isn't working anymore. Not sure what I should do now. Should I uninstall pip? What am I missing?
B/w, when trying to run pip3 uninstall -r reqs.txt -y I get errors like this:
Found existing installation: appdirs 1.4.3
Not uninstalling appdirs at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'appdirs'. No files were found to uninstall.
Found existing installation: apturl 0.5.2
Not uninstalling apturl at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'apturl'. No files were found to uninstall.
Found existing installation: blinker 1.4
Not uninstalling blinker at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'blinker'. No files were found to uninstall.
Thanks for your help!
I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv:
Copypip freeze | xargs pip uninstall -y
In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):
Copypip freeze --exclude-editable | xargs pip uninstall -y
If you have packages installed directly from github/gitlab, those will have @.
Like:
django @ git+https://github.com/django.git@<sha>
You can add cut -d "@" -f1 to get just the package name that is required to uninstall it.
Copypip freeze | cut -d "@" -f1 | xargs pip uninstall -y
This will work for all Mac, Windows, and Linux systems. To get the list of all pip packages in the requirements.txt file (Note: This will overwrite requirements.txt if exist else will create the new one, also if you don't want to replace old requirements.txt then give different file name in the all following command in place requirements.txt).
Copypip freeze > requirements.txt
Now to remove one by one
Copypip uninstall -r requirements.txt
If we want to remove all at once then
Copypip uninstall -r requirements.txt -y
If you're working on an existing project that has a requirements.txt file and your environment has diverged, simply replace requirements.txt from the above examples with toberemoved.txt. Then, once you have gone through the steps above, you can use the requirements.txt to update your now clean environment.
And For single command without creating any file as @joeb suggested
Copypip uninstall -y -r <(pip freeze)