Cannot upgrade pip - python

I try to install openai-gym library, so I run this command: pip install gym
but I got this error:
Traceback (most recent call last): File "/usr/bin/pip", line 9, in
from pip import main ImportError: cannot import name main
I searched and I got that https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main will help me, so I tried these commands: sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
but I got this error while running sudo python3 -m pip uninstall pip:
Not uninstalling pip at /usr/lib/python3/dist-packages, outside
environment /usr You are using pip version 8.1.1, however version 18.0
is available. You should consider upgrading via the 'pip install
--upgrade pip' command.
And finally when I run pip install --upgrade pip again I got this error:
Traceback (most recent call last): File "/usr/bin/pip", line 9, in
from pip import main ImportError: cannot import n
It becomes a loop and I don't know what to do?! :(

Related

ModuleNotFoundError: No module named 'pip._internal.cli'

Need some help here.
I have two versions of pip and pip3 installed in different location.
When I try to do a pip install package-name it throws Error as:
ModuleNotFoundError: No module named 'pip._internal.cli'
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ which pip
/project/miniconda/bin/pip
$ which pip3
/usr/local/bin/pip3
$ pip -V
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'```
Since I don't have super user access, I cannot modify pip._internal.cli.main to pip.internal.cli.main.
Please help.
Please upgrade pip with python -m pip install --upgrade --force-reinstall pip.
You can try to install any package with: python -m pip install package-name for python2.7 and python3 -m pip install package-name for python3.
Using python -m pip install instead of just pip install is recommended. The reason is that it will use the correct interpreter for your python installation, specially if you have many versions installed. More details here: https://snarky.ca/why-you-should-use-python-m-pip/
Try this it worked for me
python3 -m pip install --user --upgrade pip
Image Link for code

Pipenv "ModuleNotFoundError: No module named 'pip'" after upgrading to python3.7

I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...

Why is my pip braking after updating

My pip broke after I ran
pip install --upgrade pip
When I run this command
pip -V
or any other commands I get
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
Why is it breaking? I have python3 installed. I have a solution but I need to understand why it broke after upgrading to the latest version.
pip authors were warning for many years to not import pip. Finally at version 10 they restructured their code.
Your /usr/bin/pip was not upgraded (probably because pip install -U pip installed new /usr/local/bin/pip) so it uses the old API before renaming.
If that's the case I recommend to put /usr/local/bin before /usr/bin in $PATH.

Some issues with pip installation

I tried to install pip manager using the file get-pip.py as mentioned in the documentation- https://pip.pypa.io/en/stable/installing/
So, I downloaded the file and ran python get-pip.py and as a result, I had permission issues. So I again ran sudo python get-pip.py and it worked.
Now I wanted to install numpy. So I ran pip install numpy and it showed me the Import Error saying-
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
But again when I ran sudo pip install numpy, it worked and got installed. Now, for every python script involving these pip packages, I have to run the script using sudo which I don't like. So how can I resolve these permission issues?
Just to mention-
python v2.7.12
pip v9.0.1
pip installation location- /usr/local/lib/python2.7/dist-packages

Problems Installing pip on CentOS 5.x

I have pip installed:
[amr#h2oamr kits]$ python get-pip.py
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages
However, I'm getting this error when trying to install Django:
[amr#h2oamr kits]$ pip install django
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
I am stuck trying to move forward. I installed pip as recommended by using a get-pip.py module I downloaded.
This upgrade also did not work.
[amr#h2oamr kits]$ pip install --upgrade pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
How can I remove pip altogether, and then re-install it?
you can use the command $ rm pip to remove pip and then $sudo apt-get install pip to get the latest version

Categories

Resources