将 python3 作为我在 Mac 上的默认 python [英] Make python3 as my default python on Mac

查看:32
本文介绍了将 python3 作为我在 Mac 上的默认 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里要做的是将python3设为我的默认python.除了在mac上自动安装的python 2.7之外,我安装了python3自制.这是我关注的网站.http://docs.python-guide.org/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:$PATH

PATH 的顺序很重要,通过将 /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. http://docs.python-guide.org/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:$PATH

And 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 update

Next install python:

brew install python

That will install and symlink python3 to python, for more details do:

brew info python

Look 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/bin

Then add to your path /usr/local/opt/python/libexec/bin:

export PATH=/usr/local/opt/python/libexec/bin:$PATH

The 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆