在 Mac 上安装 Python3.6 和 Python3.7
Installing Python3.6 alongside Python3.7 on Mac
我正在尝试将 tensorflow 安装到带有 Python3.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
据我所知,这是因为 tensorflow 尚不支持 Python3.7。作为解决方法,我想安装 Python3.6 和 3.7,然后将 tensorflow 安装到该版本。但是,我是 Mac 的新手,不确定在不影响现有 Python 版本的情况下执行此操作的正确方法。
我试过使用 brew,但看起来 Python3 非常具体。做我想做的事情的正确方法是什么?
尝试使用 brew
例如,如果已经使用 Python 3:
$ brew unlink python
然后:
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
要返回 python 3.7.4_1
使用:
$ brew switch python 3.7.4_1
如果需要 3.6 再次切换:
$ brew switch python 3.6.5_1
当您使用系统 python 版本时,我强烈建议您使用 pyenv - 它会让生活变得更加轻松。您只需 运行
brew install pyenv
pyenv install 3.6.5
pyenv install 3.7.4
那你可以运行pyenv local [python version]
如果您正在使用 mac,您可以从 Brew 安装 pyenv,安装所需的版本,列出已安装的版本,并在本地或全局激活每个版本。
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: 全局激活需要重启电脑才能生效。您需要将 $(pyenv root)/shims
添加到 PATH
环境变量的 left 前面。
我正在尝试将 tensorflow 安装到带有 Python3.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
据我所知,这是因为 tensorflow 尚不支持 Python3.7。作为解决方法,我想安装 Python3.6 和 3.7,然后将 tensorflow 安装到该版本。但是,我是 Mac 的新手,不确定在不影响现有 Python 版本的情况下执行此操作的正确方法。
我试过使用 brew,但看起来 Python3 非常具体。做我想做的事情的正确方法是什么?
尝试使用 brew
例如,如果已经使用 Python 3:
$ brew unlink python
然后
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
要返回 python 3.7.4_1
使用:
$ brew switch python 3.7.4_1
如果需要 3.6 再次切换:
$ brew switch python 3.6.5_1
当您使用系统 python 版本时,我强烈建议您使用 pyenv - 它会让生活变得更加轻松。您只需 运行
brew install pyenv
pyenv install 3.6.5
pyenv install 3.7.4
那你可以运行pyenv local [python version]
如果您正在使用 mac,您可以从 Brew 安装 pyenv,安装所需的版本,列出已安装的版本,并在本地或全局激活每个版本。
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: 全局激活需要重启电脑才能生效。您需要将 $(pyenv root)/shims
添加到 PATH
环境变量的 left 前面。