在 Mac 上安装 Python 3.6和 Python 3.7

我正在尝试用 Python 3.7在 Mac 上安装张量流,然而,我得到了一个错误:

$ pip3 -v install tensorflow
...
Skipping link https://files.pythonhosted.org/packages/56/7a/c6bca0fe52a94ca508731d8b139e7dbd5a36cddc64c19f422f97e5a853e8/tensorflow-1.10.0rc1-cp36-cp36m-win_amd64.whl#sha256=3ab24374888d6a13d55ce2e3cf4ba0c9cd6f824723313db5322512087525cb78 (from https://pypi.org/simple/tensorflow/); it is not compatible with this Python
Could not find a version that satisfies the requirement tensorflow (from versions: )
Cleaning up...
Removed build tracker '/private/var/folders/4n/9342s4wd3jv0qzwjz8rxrygr0000gp/T/pip-req-tracker-3p60r2lo'


No matching distribution found for tensorflow

据我所知,这是因为张量流还不支持 Python 3.7。作为一个解决方案,我想在3.7旁边安装 Python3.6,然后在那个版本上安装 tensorflow。然而,我对 Mac 还是个新手,不知道如何在不影响已有 Python 版本的前提下做到这一点。

我试过用 brew,但是看起来 Python 3非常具体。我追求的正确方式是什么?

109164 次浏览

Try using brew for example if already using Python 3:

$ brew unlink python

Then install python 3.6.5:

$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

To get back to python 3.7.4_1 use:

$ brew switch python 3.7.4_1

And if need 3.6 again switch with:

$ brew switch python 3.6.5_1

When you mess around with system python versions, I strongly recommend using pyenv - it makes life so much easier. You would simply run

brew install pyenv
pyenv install 3.6.5
pyenv install 3.7.4

Then you can run pyenv local [python version]

If you are using mac, you can install pyenv from Brew, install the desired versions, list the installed versions, and activate each version locally or globally.

brew install pyenv
pyenv install 3.6.9
pyenv install 3.7.4
pyenv versions
pyenv global 3.7.4 3.6.9
$ python3.6 --version
Python 3.6.9


$ python3.7 --version
Python 3.7.4

PS: Global activation worked only after restarting the computer. You need to prepend $(pyenv root)/shims to the left of your PATH environment variable.