12

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.

Nobozarb
  • 344
  • 1
  • 12
Amir
  • 158
  • 1
  • 2
  • 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

34

Try

python -m ensurepip

This command activates pip.

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

After this you can upgrade

python -m pip install --upgrade pip

Massimo
  • 2,638
  • 2
  • 26
  • 38
  • 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
  • python install --the-absolute-utter-basics-and-still-it-wont-work – Snowcrash Jan 20 '22 at 11:26
  • 1
    This shows how useless Python is. Is it `python2` or `python3`? Who knows? Why do you have to mention `pip` twice? And why isn't `pip` installed by default anyway? And why do you have to `install` and also `upgrade`? And why does 1 have double dashes whilst the other doesn't? Groan. – Snowcrash Jan 20 '22 at 11:32
  • And is it going to work anyway? No. – Snowcrash Jan 20 '22 at 11:33
  • 1
    And why do you have `pip` and `ensurepip`? And why isn't there a `python` and an `ensurepython`? Or an `ensurepython3`? Or further drivel... – Snowcrash Jan 20 '22 at 11:34
  • I tried this and got, "no module named ensurepip" – lurker Jun 01 '22 at 15:12
6

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
  • 12,665
  • 15
  • 42
  • 74
Manish Tirkey
  • 71
  • 1
  • 3
0

Try this python -m pip install --upgrade pip

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

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
0

For Debian/Ubuntu/Linux Mint and derivatives users

Install pip using APT:

sudo apt install python3-pip
Eneko
  • 1,195
  • 1
  • 11
  • 19
0

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
  • 631
  • 8
  • 15