brew install不链接python3

时间:2018-08-16 21:10:47

标签: python-3.x macos python-2.7

我在链接python3并将python3设置为默认python时遇到问题。

MacOS 10.13.6

这就是我所做的:

$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ xcode-select --version
xcode-select version 2349.
$ brew install python
...

Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin
...

它不起作用。 python仍为2。*

$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ pip --version
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 --version
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

我做到了:

$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ brew install python3
...

Warning: python 3.7.0 is already installed and up-to-date
To reinstall 3.7.0, run `brew reinstall python`
$ brew reinstall python

也不起作用

$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0

1 个答案:

答案 0 :(得分:2)

我假设您的意思是您要命令python启动 Python3 解释器,并希望pip启动pip3

提示在消息中

  

未版本化的符号链接pythonpython-configpip等指向   python3python3-configpip3等已分别安装到     / usr / local / opt / python / libexec / bin

这意味着... ”如果您希望命令python启动python3,而pip启动pip3,则需要输入{{1 }}放在您的PATH开头。”

因此,在您的登录脚本(/usr/local/opt/python/libexec/bin或类似名称)中,您需要输入:

$HOME/.profile

然后注销并重新登录以使其生效。


顺便说一句,export PATH=/usr/local/opt/python/libexec/bin:$PATH 仅意味着... “在brew link python3中创建一个指向/usr/local/bin/python3的符号链接”

您可以通过以下方式查看该链接及其指向的位置:

/usr/local/Cellar/python/3.7.0/python3