Force uninstall of the package pip - python

I'm sorry if this is a repeat question, but whenever I search force uninstall of pip I get something like a pip uninstall command. What I want is a way to uninstall the package pip (and reinstall). when I run python3 -m pip uninstall pip setuptools in a conda enviroment I get this error:
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Found existing installation: setuptools 45.2.0
Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'setuptools'. No files were found to uninstall.
I also get the same error in the base enviroment when I run /usr/lib/python3 -m pip uninstall pip setuptools.
However when I'm outside of a virtual enviroment (base) and I just run python3 -m pip uninstall pip setuptools, I get:
/home/cameron/anaconda3/bin/python3: No module named pip
I could just remove the file but I want to avoid if that would be problematic.
The problematic thing is I can still install things with pip in my base enviroment but I can't call python programs in my virtual enviroments anymore nor install new ones with pip (perhaps able to with conda) since it defaults to the packages installed with this pip even in a venv.

this should remove pip from your active conda environment
conda uninstall pip --force

I was finally able to remove with sudo apt-get purge python3-pip

Related

pip install package with --user and without --user, now I want to uninstall package installed without --user

First, I run
pip install virtualenv
and later, I run
pip install --user virtualenv
So, this is what I have now
$ which -a virtualenv
/Users/admin/.local/bin/virtualenv
/usr/local/bin/virtualenv
This is my default virtualenv
/Users/admin/.local/bin/virtualenv
Now I want to uninstall, this,
/usr/local/bin/virtualenv
What should I do?
Thanks!
I tried
pip uninstall virtualenv
It removed /usr/local/bin/virtualenv, the system wide package.
The package I installed using --user flag, which cannot be uninstalled.
I just manually removed the folder.
See this thread.
How to uninstall a package installed with pip install --user

Environment Error [Errno 2] while installing pip packages or upgrading pip

pip used to work fine until recently. First I was trying to install a pip-package using
pip install -e [some-git-link]
and I get the error
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/home/me/.local/lib/python2.7/site-packages/pip-19.0.1.dist-info/METADATA'
I then cd'ed into site-packages and the folder is empty. Indeed, I have pip installed in dis-packages and its version is 18.1, not 19.0!
I tried to update pip through
pip install -U pip
but I get the same error.
Typing
pip --version
I get
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/init.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
warnings.warn(warning, RequestsDependencyWarning)
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
so it seems that pip 18.1 is installed. Indeed, if I try
sudo apt-get install python-pip
I get
python-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 62 not upgraded.
I was wondering if all these problems were coming from the warning on the cryptography, and so I tried to do
sudo pip install --upgrade cryptography
but obviously I go back to the same Environment Error.
Thou shalt not use sudo with pip. Using sudo with pip is asking for trouble. When you do that you are having pip and your OS's package manager get into a fight. When they fight no one wins, least of all your Python installation and personal sanity. I know countless tutorials tell you to sudo pip install, but they are not your friends. The only safe and reliable way to maintain a functional Python installation is to let your OS's package manager manage what it wants to manage and either use pip install --user or virtual environments (using either virtualenv or optionally python -m venv if you're on Python 3).
I really can't stress enough that you will constantly be running into little weird things (and occasional catastrophic problems) within your Python installation if you persistently sudo install things. Learn to love virtual environments! You can even modify your shell's PATH so that things you install in an environment are available as commands (which is commonly why people think they need sudo pip install).
You could test to update PythonOpenSSL :
$ sudo python -m easy_install --upgrade pyOpenSSL
If not Ok, please do :
$ sudo pip install --upgrade cryptography
But error with : $ sudo pip
So do after :
$ sudo python -m easy_install --upgrade pyOpenSSL
Have Fun,
Johan MRe
I was getting this error trying to install packages while building a Docker image (with python:3.8 as base). Upgrading pyOpenSSL as #Johan MRe suggested solved it for me.
RUN python3 -m easy_install --upgrade pyOpenSSL
How to deal with "Could not install packages due to an EnvironmentError" when upgrade pip
First run command line in Administration mode both window and OS:
Next,
For windows: use this command to upgrade pip
python -m pip install --user --upgrade pip
For MacOS:
sudo python -m pip install --user --upgrade pip

How can I make a post virtualenv hook in pyenv to upgrade pip packages

I am using pyenv to manage different Python versions on my machine, and pyenv-virtualenv to manage my venvs. When I create a new venv with something like pyenv virtualenv foo it doesn't install the latest version of pip, setuptools, and wheel into the venv. I would like to run pip install --upgrade pip setuptools wheel inside each venv after it has been created.
pyenv has the concept of hooks for before and after a command. I am able to run this command by adding the following file
~/.pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/virtualenv/after.bash
with the following contents
after_virtualenv 'pip install --upgrade pip setuptools wheel'
The command is run, but it is not run inside the venv, so it just uses the current pip. How can I call this command inside the venv in the after_virtualenv hook?
Okay I figured it out you can just specify just created virtualenv name as the PYENV_VERSION and call pyenv-exec.
upgrade_packages() {
PYENV_VERSION=$VIRTUALENV_NAME pyenv-exec pip install --upgrade pip setuptools wheel
}
after_virtualenv 'upgrade_packages'

Upgrade pip in Amazon Linux

I wanted to deploy my Python app on Amazon Linux AMI 2015.09.1, which has Python2.7 (default) and pip (6.1.1). Then, I upgraded the pip using the command:
sudo pip install -U pip
However, it seemed broken, and showed the message when I tried to install packages:
pkg_resources.DistributionNotFound: pip==6.1.1
I found out that pip remove the previous files located in /usr/bin/, and installed the new one in /usr/local/bin. Thus, I tried to specify the location by using the command:
sudo pip install -U --install-option="--prefix='/usr/bin'" pip
Nevertheless, it still installed the new one in /usr/local/bin. In addition to that, pip could not work well with sudo although it successfully installed. The error message :
sudo: pip2.7: command not found
Is there a way to properly manage pip?
Try:
sudo which pip
This may reveal something like 'no pip in ($PATH)'.
If that is the case, you can then do:
which pip
Which will give you a path like /usr/local/bin/pip.
Copy + paste the path to pip to the sbin folder by running: sudo cp /usr/local/bin/pip /usr/sbin/
This will allow you to run sudo pip without any errors.
Struggled with this for a while. Here's what I've found:
ec2_user finds the pip executable, but has a module import error due to other having no read/execute permissions on the pip folders in the /usr/local/lib/python2.7/site-packages folder. This is actually okay, since in most cases, pip installs fail when not run as root anyway.
sudo cannot find pip.
Entering root with sudo su - allows pip to be run without issue.
The reason sudo pip stops working after the upgrade, is because the executable (or symbolic link) is removed from /usr/bin. However, what remains is a file called pip-27, which contains the following:
#!/usr/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==6.1.1','console_scripts','pip2.7'
__requires__ = 'pip==6.1.1'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==6.1.1', 'console_scripts', 'pip2.7')()
)
So, that's where our error comes from, as the upgrade clearly doesn't clean this file up. Not entirely clear on where the name translation from pip to pip-2.7 occurs.
As mentioned in another answer, pip now exists in /usr/local/bin after the upgrade, which is no longer in the sudo secure path. You can add this path to the secure_path variable by running sudo visudo. Another alternative, if you'd prefer to not add that path to your secure_path is to make a symbolic link to the new pip executable in /usr/bin.
The problem is partly answered by your question. The Amazon AMI doesn't consider /usr/local/bin to be part of the root account's PATH. You can fix this by updating the root account's ~/.bashrc to include it.
Something like this...
export PATH=$PATH:/usr/local/bin
After struggling with this for hours and reading comments
which pip gave /usr/bin/pip , but the actual pip was located at /usr/local/bin/pip due to pip upgrade and clean up was not complete
So removing the pip in /usr/bin/
sudo rm /usr/bin/pip
and also adding the new pip to your export path
vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/bin
exit terminal, and login back
which pip should give /usr/local/bin/pip
pip install --upgrade pip
This works for me
sudo /usr/local/bin/pip install --upgrade pip
To add to angelokh
sudo `which pip` install --upgrade pip
I think the best strategy in this case is to manage pip is as part of a virtual environment using virtualenv rather than messing with the system-level version.
If you're OK with that, here's the basic idea:
Install the version of virtualenv packaged with the version of pip you are looking to upgrade to to the system-level pip (e.g. virtualenv==15.1.0 comes with pip==9.0.1):
$ sudo pip install -U virtualenv==15.1.0
You are using pip version 6.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting virtualenv==15.1.0
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |████████████████████████████████| 1.8MB 135kB/s
Installing collected packages: virtualenv
Found existing installation: virtualenv 12.0.7
Uninstalling virtualenv-12.0.7:
Successfully uninstalled virtualenv-12.0.7
Successfully installed virtualenv-15.1.0
I used the virtualenv release notes to find out which version of pip corresponds to which version of virtualenv.
Create the virtual environment:
$ virtualenv myenv
New python executable in /home/ec2-user/myenv/bin/python2.7
Also creating executable in /home/ec2-user/myenv/bin/python
Installing setuptools, pip, wheel...done.
Activate the virtual environment and confirm the version and location of the upgraded pip:
$ source myenv/bin/activate
(myenv) $ pip -V
pip 9.0.1 from /home/ec2-user/myenv/local/lib/python2.7/dist-packages (python 2.7)
(myenv) $ which pip
~/myenv/bin/pip
This should allow you to install packages to this virtualenv using the pip version of your choice, without the need for sudo.
I think you've didn't installed the pythonXX-pip package.
I've upgraded mine straight to Python3.4, these commands works for me.
sudo su
yum install python34
yum install python34-pip

Can't pip install packages in Anaconda

I broke conda somehow by updating it. If there was a package pack that I couldn't get using
conda install pack
I could do
pip install pack
and everything worked great. That package would then be accessible from the python in anaconda/bin/python.
After running conda update conda, pip corresponds not to the conda environment but to the base python on osx (I think).
which pip
/usr/local/bin/pip
I tried navigating to the pip package in the anaconda folder. But even running
pip install pack
from there installs the package in /Library/Python/2.7/site-packages and not in //anaconda. Any ideas on how to fix this? Thanks!
Edited:
which conda
/Users/Ben/anaconda/bin/conda
echo$PATH
bash:echo/Users/Ben/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin://anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Ben/anaconda/bin:/opt/X11/bin:/usr/texbin: No such file or directory
Try conda update pip or conda update -f pip to force it.
You should get rid of the original OS python pip, use:
With Debian/Ubuntu:
sudo apt-get purge python-pip
With Redhat/Centos/Fedora:
sudo yum remove python-pip
That was referenced here: https://unix.stackexchange.com/questions/187701/how-do-i-correct-the-path-for-pip

Categories