25

1

I can't use pip and I don't know why.

The error I get is shown below:

  File "d:\python\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "d:\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

If I try py -3.8 -m pip install I get D:\Python\python.exe: No module named pip.

If I use get-pip nothing happens.

If I try to upgrade pip nothing happens.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Amir
  • 388
  • 1
  • 4
  • 7
  • Did you re-install python and all tools ? – tafhim May 02 '20 at 14:47
  • Did you try using pip3? –  May 02 '20 at 14:52
  • tafhim | no i don´t have re-install python and all tools maby i can find another way – Amir May 02 '20 at 15:07
  • yovel cohen | Yes i did – Amir May 02 '20 at 15:07
  • How did you install `python`? Was this error there from the beginning or did it appear after you did something specific? – FlyingTeller May 02 '20 at 15:43
  • @Amir You shouldn't need to reinstall all your tools. Try just reinstalling python itself and see if that fixes it. – Nobozarb May 02 '20 at 16:25
  • Does this answer your question? [How to fix ModuleNotFoundError: No module named 'pip.\_internal' with python source code installation](https://stackoverflow.com/questions/56361133/how-to-fix-modulenotfounderror-no-module-named-pip-internal-with-python-sour) – Eneko Sep 16 '21 at 15:01

6 Answers6

50

Following pip installation, try this on Windows

py -m ensurepip --upgrade

This command activates pip.

Ref. https://docs.python.org/3/library/ensurepip.html

After this you can upgrade

python -m pip install --upgrade pip

or, on Windows

py -m pip install -U pip
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Massimo
  • 3,171
  • 3
  • 28
  • 41
  • 1
    C:\Users\Amir>python -m ensurepip C:\Users\Amir>python -m pip install --upgrade pip Nothing happened – Amir May 02 '20 at 21:00
  • Amir, call the python executable by its full pathname or add its installation directory to the system variable PATH. – Massimo May 03 '20 at 01:06
  • 3
    I tried this and got, "no module named ensurepip" – lurker Jun 01 '22 at 15:12
  • `python -m pip install --upgrade pip` uninstalls pip for me lmao python pls .-. `ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied` `Uninstalling pip-22.0.4` – Farzher Nov 02 '22 at 06:02
  • @Snowcrash Why are you using Python2 when it is end-of-life? `pip` can upgrade itself, therefore why it is listed twice. And short-args with single dash vs two for long-opts are CLI semantics, not a Python issue... The Python installer "ensures Python"... Not all OS come with Pip installed, therefore why it needs "ensured" via code that it does come with. – OneCricketeer Apr 04 '23 at 18:15
  • @OneCricketeer because Python and Pip is hard to upgrade. e.g. on the old Mac I occasionally use, the system Python is 2.7 (from memory) and no upgrade path is offered. So, you end up upgrading in userspace but, if you haven't aliased correctly, it's easy to end up using the system python. – Snowcrash Apr 12 '23 at 15:30
  • @Snowcrash I see. However Mac system python won't let you run `get-pip.py` without `sudo` (which should be avoided). It is not "hard to upgrade" IMO, following https://python.org/downloads . `pip` has come with Python installation since version 3.4. Otherwise, people often use Anaconda or `pyenv` + `brew` to install those. Where, you should almost always prefer `python3` alias over just `python` – OneCricketeer Apr 12 '23 at 17:18
14

I had the same problem. But in my case, when I was upgrading the pip version the new version stopped installing (upgrading) before the older version successfully uninstalled. After searching 4 or 5 sites I found:

python -m ensurepip

I was able to use the pip command and also this:

python -m pip install --upgrade pip
Tonechas
  • 13,398
  • 16
  • 46
  • 80
Manish Tirkey
  • 171
  • 1
  • 5
4

For Debian/Ubuntu/Linux Mint and derivatives users

Install pip using APT:

sudo apt install python3-pip
Eneko
  • 1,709
  • 1
  • 16
  • 25
3

I don't know what OS you are using and what errors you got when using get-pip, but I had similar issue on Ubuntu20 and this solved it:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

Credit: @Benjamin's answer here: https://askubuntu.com/questions/1025189/pip-is-not-working-importerror-no-module-named-pip-internal

pegah
  • 791
  • 8
  • 15
0

Try this python -m pip install --upgrade pip

A suggestion, try to use anaconda or venv to avoid such issues.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
akibkamani
  • 41
  • 6
0

I had the same problem, but found that python -m ensurepip just told me that the pip scripts were already installed. So what I did was delete the 2 pip directories under C:\Users\[user_id]\AppData\Local\Programs\Python\Python38\Lib\site-packages, then run python -m ensurepip again. That fixed it for me.

squeakyD
  • 628
  • 5
  • 5