简体   繁体   English

Python 官方最新版本、Homebrew 版本和安装版本在 macOS 上有所不同

[英]Python official newest version, Homebrew version and installed version differ on macOS

  1. According to python.org , 3.8.2 is currently the latest version of Python.根据python.org ,3.8.2 目前是 Python 的最新版本。
  2. When I try to upgrade python3 using Homebrew (freshly upgraded), it tells me version 3.7.6_1 is already installed.当我尝试使用 Homebrew(刚升级)升级 python3 时,它告诉我 3.7.6_1 版本已经安装。
  3. When I ask python3 for it's current version, it tells me 3.7.3.当我询问 python3 的当前版本时,它告诉我 3.7.3。

See terminal runs:查看终端运行:

Nannas-Computer:some_folder username$ brew update
Already up-to-date.
Nannas-Computer:some_folder username$ brew upgrade
Nannas-Computer:some_folder username$ brew upgrade python3
Warning: python3 3.7.6_1 already installed
Nannas-Computer:some_folder username$ python3 --version
Python 3.7.3

Why are all these versions different, and how can I install the 3.8.2 version on my mac (macOS Mojave, version 10.14.6)?为什么所有这些版本都不同,我如何在我的 Mac(macOS Mojave,版本 10.14.6)上安装 3.8.2 版本?

You can install Python 3.8.x using command:您可以使用以下命令安装 Python 3.8.x:

brew install python@3.8

As it's not main Python distribution on Homebrew, by default it's not accessible by simple typing python3 .由于它不是 Homebrew 上的主要 Python 发行版,因此默认情况下无法通过简单输入python3访问它。 Binary is located in /usr/local/Cellar/python@3.8/3.8.2/bin/python3.8 and you can create a symlink to it or use directly by typing full path.二进制文件位于/usr/local/Cellar/python@3.8/3.8.2/bin/python3.8 ,您可以创建指向它的符号链接或通过键入完整路径直接使用。

It's not that cumbersome as one may think because usually the only thing you need to do is to create a virtual environment and activate it.这并不像人们想象的那么麻烦,因为通常您唯一需要做的就是创建一个虚拟环境并激活它。 Since then it'll be your default Python (for this virtualenv):从那时起,它将成为您的默认 Python(对于此 virtualenv):

$ /usr/local/Cellar/python@3.8/3.8.1/bin/python3.8 -m venv my_venv
$ source my_venv/bin/activate
(my_venv)$ python
Python 3.8.1 (default, Dec 27 2019, 18:06:00)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

After some research I found out the following reasons:经过一番研究,我发现了以下原因:

  • It is possible to upgrade to Python 3.8.2 via Homebrew, but it isn't listed as supplying python due to some complications.可以通过 Homebrew 升级到 Python 3.8.2,但由于一些复杂性,它没有被列为提供 python。 See status here .在此处查看状态。 Until this issue is done, 3.7.6_1 is the newest version you can upgrade to (as Homebrew kept telling me).在此问题完成之前,3.7.6_1 是您可以升级到的最新版本(正如 Homebrew 一直告诉我的那样)。

  • When I ran python3 --version in terminal, it returned Python 3.7.3 because I had installed this version myself at some point from the official website, without using Homebrew.当我在终端中运行python3 --version时,它返回Python 3.7.3因为我自己在某个时候从官方网站安装了这个版本,没有使用 Homebrew。 Upgrading python to 3.7.6 via Homebrew had no effect on this dominating installation of python.通过 Homebrew 将 python 升级到 3.7.6 对 python 的这种主要安装没有影响。 I got rid of the manually installed version using this useful answer, after which I reinstalled python properly using Homebrew just to be on the safe side and now I finally have:我使用这个有用的答案摆脱了手动安装的版本,之后我使用 Homebrew 正确重新安装了 python 只是为了安全起见,现在我终于有了:

     Nannas-Computer:some_folder username $ python3 --version Python 3.7.6

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM