1

When I use pip3 I get this error:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
    from pip import main
ModuleNotFoundError: No module named 'pip'

I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip

It told me to install Xcode command line

$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    What are you trying to achieve by importing `pip`? I don't think I've seen anyone do that before – lucidbrot Jun 09 '22 at 08:08
  • 1
    i want ```pip3 install aiohttp``` ,But it tells me ```Traceback (most recent call last): File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in from pip import main ModuleNotFoundError: No module named 'pip'``` – futer_dream Jun 09 '22 at 08:10
  • 1
    Ah, I think I misunderstood. Is this an error that you get when you run pip? in that case, [this](https://stackoverflow.com/a/56896098/2550406) looks related and my guess is that you do need to install python first - like the xcode message tells you – lucidbrot Jun 09 '22 at 08:10
  • 1
    I have been using Python for a long time, but I don't know why this error occurs – futer_dream Jun 09 '22 at 08:13
  • 1
    @futer_dream https://xkcd.com/1987/ - thats why .. – rasjani Jun 09 '22 at 08:20
  • You could try running pip as a module? `python3 -m pip ...` – Tzane Jun 09 '22 at 08:34

2 Answers2

1

I had this problem when I was trying to update the pip and it failed. This always works for me:

python get-pip.py

font: https://pip.pypa.io/en/stable/installation/

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Try to install python3.9 as suggested by the terminal.

Dharman
  • 30,962
  • 25
  • 85
  • 135
narwhal
  • 43
  • 3