简体   繁体   English

自制 python 版本与 Mac python 版本不同?

[英]Homebrew python version different than Mac python version?

I've searched a while and haven't found an answer to this particular issue.我已经搜索了一段时间,但没有找到这个特定问题的答案。

brew info python returns python: stable 3.7.7 (bottled), HEAD brew info python返回python: stable 3.7.7 (bottled), HEAD

However, python -V and python3 -V return Python 3.6.1:: Anaconda 4.4.0 (x86_64)但是, python -Vpython3 -V返回Python 3.6.1:: Anaconda 4.4.0 (x86_64)

Why is my Mac python version different than what I've installed with HB, and how can I fix it?为什么我的 Mac python 版本与我使用 HB 安装的版本不同,我该如何解决? Thank you!谢谢!

One version of python was installed using the Anaconda distribution.使用 Anaconda 发行版安装了 python 的一个版本。 The other by Homebrew.另一个是自制的。 It's not surprising that they are different versions.它们是不同的版本也就不足为奇了。 You should run in virtual environments and then you won't need to worry about 2 versions.您应该在虚拟环境中运行,然后您无需担心 2 个版本。 Using the Anaconda distribution it is easy to set up a virtual environment to run that version.使用 Anaconda 发行版可以轻松设置虚拟环境来运行该版本。

Erg.尔格。 Yes—this is a challenge sometimes.是的——有时这是一个挑战。 macOS ships with python as part of its system. macOS 随附 python 作为其系统的一部分。 Catalina 10.15.4 ships with /usr/bin/python3 of 3.7.3. Catalina 10.15.4 附带 3.7.3 的 /usr/bin/python3。 brew (at the moment) has installed 3.7.7 as its stable branch, but it also offers a python@3.8 which installs 3.8.2. brew(目前)已安装 3.7.7 作为其稳定分支,但它还提供了一个安装 3.8.2 的 python@3.8。 That's significant because there are other brew packages (notably vim) which specity python@3.8 as a dependency.这很重要,因为还有其他 brew 包(尤其是 vim)将 python@3.8 指定为依赖项。 Yuck.呸。

I'm not running anaconda at the moment, but I'll take your word that it's yet-another version.我现在没有运行 anaconda,但我相信你的话,它是另一个版本。

Whichever appears first in your path is going to prevail unless you're operating inside a context like a virtual environment.除非您在诸如虚拟环境之类的上下文中操作,否则无论哪个先出现在您的路径中都会占上风。 You can arrange your path to set your preferred python3 to run.你可以安排你的路径来设置你喜欢的 python3 来运行。 You can always check which python3 is running by using "which python3" and that will give you the full path of the running program.您始终可以使用“which python3”检查正在运行的 python3,这将为您提供正在运行的程序的完整路径。

Word of caution: Each distinct python3 will maintain its own packages library.注意事项:每个不同的 python3 都将维护自己的包库。 Once you have your paths sorted out, you should manage your packages with "python3 -m pip " to be sure you're managing the libraries for your intended version.整理好路径后,您应该使用“python3 -m pip”管理您的包,以确保您正在管理您想要的版本的库。

And yes—eventually, it'd probably be good for us to work in virtual environments or skip straight to Docker containers.是的——最终,在虚拟环境中工作或直接跳到 Docker 容器可能对我们有好处。

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

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