9

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'
2

2 Answers 2

14
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.

4
  • I can run pip3 -V outside pipenv. But not in pipenv.
    – JOHN
    Mar 12, 2020 at 4:38
  • Search the documentation for that
    – Shamsheer
    Jul 31, 2020 at 16:51
  • The force-install worked for me on Mac OS 10.14 after upgrading from Python 3.7.7 to 3.8.5 and trying to run a venv-generated virtual environment. I think it might have something to do with symlinks.
    – ingernet
    Oct 12, 2020 at 18:00
  • Great python3 get-pip.py --force-reinstall this line did the trick
    – dhiraj
    Jan 27, 2021 at 7:46
-1

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.