简体   繁体   English

MacOS Catalina 上的两个不同的 Python3 和两个不同的 Python2 安装

[英]Two different Python3 and Two different Python2 installations on MacOS Catalina

I have an issue, when using Visual Studio Code, and when I'm choosing the interpreter of Python to use within a code, I realize there are two different installations or Python 3, besides the two Python2 installations.我有一个问题,在使用 Visual Studio Code 时,当我选择 Python 的解释器在代码中使用时,我意识到除了两个 Python2 安装之外,还有两个不同的安装或 Python 3。

  • Python 3.7.3 on /usr/bin/python3 /usr/bin/python3 上的 Python 3.7.3
  • Python 3.8.2 on /usr/local/bin/python3 /usr/local/bin/python3 上的 Python 3.8.2
  • Python 2.7.16 on /usr/bin/python (I guess this is the Apple version) /usr/bin/python 上的 Python 2.7.16(我猜这是 Apple 版本)
  • Python 2.7.17 on /usr/local/bin/python Python 2.7.17 在 /usr/local/bin/python

The problem comes when I'm trying to use the 'Extract Method' on the 3.8.2 and it tells me to update pip.当我尝试在 3.8.2 上使用“提取方法”时出现问题,它告诉我更新 pip。 How do I choose the installation to update pip?如何选择安装更新pip?

When I run "sudo pip install --upgrade pip" it only goes to the python 2 apple version.当我运行“sudo pip install --upgrade pip”时,它只会转到 python 2 苹果版本。 But I can't update the pip on the other installations.但我无法在其他安装上更新 pip。

Thanks in advance.提前致谢。

You can run python -m pip to run pip with a particular Python version.您可以运行python -m pip以使用特定的 ZA7F5F35426B927411FC9231B53Z 版本运行pip So所以

sudo /usr/[local/]bin/python[3] -m pip install --upgrade pip

Square brackets [] mean optional parts.方括号[]表示可选部分。

  1. First new version of MacOs are built in python2 and python3 in usr/bin第一个新版本的 MacOs 内置在 usr/bin 中的 python2 和 python3 中

  2. just leave them and install newest python离开它们并安装最新的 python

  3. then edit path which in /etc/paths put 'usr/local/bin' on the first line然后编辑在 /etc/paths 中将 'usr/local/bin' 放在第一行的路径

  4. enjoy.请享用。 now all your python3 is run in usr/local/bin which is newest and installed by yourself.现在你所有的 python3 都在 usr/local/bin 中运行,它是最新的并由你自己安装。 Also pip is work too. pip 也可以工作。 if you wanna upgrade your python just run brew upgrade.如果你想升级你的 python 只需运行 brew upgrade 。 It's best way to use python on mac and DONT DELETE default python2 and 3 just leave them这是在 mac 上使用 python 和 DONT DELETE 默认 python2 和 3 的最佳方法,只需保留它们

As said in Upgrading pip for different versions of python , you can:为不同版本的 python 升级 pip 中所述,您可以:

Use the python 3.8 interpreter to run the command:使用 python 3.8 解释器运行命令:

python3.8 -m pip install --upgrade pip

Or use the pip3.8 binary directly:或者直接使用 pip3.8 二进制文件:

pip3.8 install --upgrade pip

Note that if the Python command is not in your PATH, you must provide the full path when running the upgrade:请注意,如果 Python 命令不在您的 PATH 中,则必须在运行升级时提供完整路径:

/usr/local/bin/python3 install --upgrade pip 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python2和python3中的pytest-不同的行为 - Pytest in python2 and python3 - different behaviour 无法在 Python3 中导入 tkinter,但它可以在 python2 (Python3.7 macOS Catalina) 中工作 - Unable to import tkinter in Python3, but it works in python2 (Python3.7 macOS Catalina) pyaudio在python2 vs python3中播放不同的音调 - pyaudio plays different tones in python2 vs python3 如何为python3和python2分别设置不同的PYTHONPATH变量 - how to set different PYTHONPATH variables for python3 and python2 respectively easy_install是否与python2和python3不同? - easy_install is different for python2 and python3 or not? 相同代码在python3和python2之间的运行结果不同 - different run results between python3 and python2 for the same code 为什么python2和python3的print输出同一个字符串不同? - Why is the output of print in python2 and python3 different with the same string? 在Python2和Python3中编写不同的十六进制值 - Write different hex-values in Python2 and Python3 为什么代码在 python2 和 python3 中有不同的行为? - Why the code has different behavior in python2 and python3? 为什么 Python2 和 Python3 的行为不同 - Why the behavior is different between Python2 and Python3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM