我在这里要做的是将python3设为我的默认python.除了在mac上自动安装的python 2.7之外,我安装了python3和自制.这是我关注的网站.docs.python-guide/en/latest/starting/install3/osx/#install3-osx
我想我很好地遵循了每一条指令,新安装了 xcode、命令行工具和自制软件.但这是我的小困惑.
该脚本将解释它将进行哪些更改并在安装开始前提示您.安装 Homebrew 后,在 PATH 环境变量的顶部插入 Homebrew 目录.您可以通过在 ~/.profile 文件的底部添加以下行来做到这一点
导出路径=/usr/local/bin:/usr/local/sbin:$PATH
我真的很困惑这是什么,但我得出的结论是我应该在 ~/.profile 文件的底部添加以下行.所以我在终端中通过 open .profile 打开了 ~/.profile 文件,并在底部添加了以下行.现在看起来像这样.
export PATH=/usr/local/bin:/usr/local/sbin:$PATH# 为 Python 3.6 设置 PATH# 原始版本保存在.profile.pysave导出路径=/usr/local/bin:/usr/local/sbin:$PATH然后我做了 brew install python,并希望在我做 python --version 时看到 python3.但它只是向我展示了 python 2.7.10. 我希望我的默认 python 是 python3 而不是 2.7
我从网站上找到了一点线索.
我是否安装了 Python 3?
$ python --version蟒蛇 3.6.4如果您仍然看到 2.7 确保 PATH/usr/local/bin/优先于/usr/bin/
也许它必须对 PATH 做一些事情? 有人可以用简单的英语解释一下 PATH 到底是什么,以及我如何在运行时使我的默认 python 成为 python3python --version 在终端?
解决方案可能最安全和简单的方法是使用 brew 然后只需修改您的 PATH:
第一次更新brew:
brew 更新下一步安装python:
brew install python这将安装python3并将其符号链接到python,有关更多详细信息,请执行:
brew info python寻找注意事项:
==>注意事项Python已安装为/usr/local/bin/python3未版本化的符号链接 `python`、`python-config`、`pip` 等指向`python3`、`python3-config`、`pip3` 等,分别安装到/usr/local/opt/python/libexec/bin然后添加到你的路径/usr/local/opt/python/libexec/bin:
export PATH=/usr/local/opt/python/libexec/bin:$PATHPATH 的顺序很重要,通过将 /usr/local/opt/python/libexec/bin 放在首位将有助于优先安装 brew(python3) 而不是位于 /usr/bin/python
的系统中What I'm trying to do here is to make python3 as my default python. Except the python 2.7 which automatically installed on mac, I installed python3 with homebrew. This is the website that I'm following. docs.python-guide/en/latest/starting/install3/osx/#install3-osx
I guess I followed every instruction well, got xcode freshly installed, Command line tools, and homebrew. But here's my little confusion occurs.
The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
I was really confused what this was, but I concluded that I should just add this following line at the bottom of ~/.profile file. So I opened the ~/.profile file by open .profile in the terminal, and added following line at the bottom. And now it looks like this.
export PATH=/usr/local/bin:/usr/local/sbin:$PATH # Setting PATH for Python 3.6 # The original version is saved in .profile.pysave export PATH=/usr/local/bin:/usr/local/sbin:$PATHAnd then I did brew install python, and was hoping to see python3 when I do python --version. But it just shows me python 2.7.10. I want my default python to be python3 not 2.7
And I found a little clue from the website.
Do I have a Python 3 installed?
$ python --version Python 3.6.4
If you still see 2.7 ensure in PATH /usr/local/bin/ takes pecedence over /usr/bin/
Maybe it has to do something with PATH? Could someone explain in simple English what PATH exactly is and how I could make my default python to be python3 when I run python --version in the terminal?
解决方案Probably the safest and easy way is to use brew and then just modify your PATH:
First update brew:
brew updateNext install python:
brew install pythonThat will install and symlink python3 to python, for more details do:
brew info pythonLook for the Caveats:
==> Caveats 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/binThen add to your path /usr/local/opt/python/libexec/bin:
export PATH=/usr/local/opt/python/libexec/bin:$PATHThe order of the PATH is important, by putting first the /usr/local/opt/python/libexec/bin will help to give preference to the brew install (python3) than the one is in your system located in /usr/bin/python
更多推荐
将 python3 作为我在 Mac 上的默认 python
发布评论