Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

python - pip defaults to python3

My Python is MESSED UP. I recently installed python3.6 and python3.7 using ppa:deadsnakes/ppa. I think I also may have tried to reinstall python 2.7 and python 3.5 (which I now understand is a big no-no because some OS features depend on proper Python always being configured). And there may have been other changes.

Currently:

python --version

Python 2.7.12

python2 --version

Python 2.7.12

python3 --version

Python 3.7.9

And I get the following:

pip -V

Traceback (most recent call last):
  File "/home/<my_user>/.local/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/home/<my_user>/.local/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

Which seems like pip contains python3 code, but is running python2.

Indeed:

python3 -m pip -V

gives

pip 21.0 from /home/<my_user>/.local/lib/python3.7/site-packages/pip (python 3.7)

Note that this is after I tried changing the first line of /home/<my_user>/.local/bin/pip to:

#!/usr/bin/python

(it was originally python3)

Does someone understand what's happening? How can I get pip -V to return a version associated with python2 instead of crashing?

I'm running Ubuntu 16.04 LTS.

question from:https://stackoverflow.com/questions/65890755/pip-defaults-to-python3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...