Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 871
JOHN Avatar asked Mar 12 '20 04:03

JOHN


People also ask

How to fix the Python “modulenotfounderror” “no module named “Pip”?

The Python "ModuleNotFoundError: No module named 'pip'" occurs when pip is not installed in our Python environment. To solve the error, install the module by running the python -m ensurepip --upgrade command on Linux or MacOS or py -m ensurepip --upgrade on Windows. Open your terminal and run the following command to install pip.

Can Pip be used after upgrading?

Sign in to your account After upgraded, pip can not be used. It produced the error "ModuleNotFoundError: No module named 'pip._vendor' "

Do I need to run PIP3 in elevated mode?

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. Had the same issue on macOS as well, it's a common issue across platforms.


1 Answers

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.

like image 86
Shamsheer Avatar answered Nov 07 '22 19:11

Shamsheer