简体   繁体   中英

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

However, python -V and python3 -V return 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? Thank you!

One version of python was installed using the Anaconda distribution. 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. Using the Anaconda distribution it is easy to set up a virtual environment to run that version.

Erg. Yes—this is a challenge sometimes. macOS ships with python as part of its system. Catalina 10.15.4 ships with /usr/bin/python3 of 3.7.3. 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. That's significant because there are other brew packages (notably vim) which specity python@3.8 as a dependency. Yuck.

I'm not running anaconda at the moment, but I'll take your word that it's yet-another version.

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. You can always check which python3 is running by using "which python3" and that will give you the full path of the running program.

Word of caution: Each distinct python3 will maintain its own packages library. 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.

And yes—eventually, it'd probably be good for us to work in virtual environments or skip straight to Docker containers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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