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

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

问题描述

我要在此处执行的操作是将python3设置为我的默认python.除了在Mac上自动安装的python 2.7之外,我使用安装了 python3 >自制.这是我关注的网站. http://docs.python-guide.org/zh/latest/starting/install3/osx/#install3-osx

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

我想我很好地遵循了每条指令,重新安装了xcode,命令行工具和自制软件.但这是我的小困惑.

I guess I followed every instruction well, got xcode freshly installed, Command line tools, and homebrew. But here's my little confusion occurs.

该脚本将说明它将进行哪些更改,并在安装开始之前提示您.安装Homebrew后,将Homebrew目录插入PATH环境变量的顶部.为此,您可以在〜/.profile文件底部添加以下行

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

导出PATH =/usr/local/bin:/usr/local/sbin:$ PATH

我真的很困惑这是什么,但是我得出的结论是,我应该只在〜/.profile文件的底部添加以下行.因此,我在终端中通过 open .profile 打开了〜/.profile 文件,并在底部添加了以下行.现在看起来像这样.

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

然后我做了 brew安装python ,并希望当我进行 python --version时看到 python3 . 但这只是向我显示了 python 2.7.10..我希望我的默认python是 python3 而不是2.7

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.

我是否安装了Python 3?

Do I have a Python 3 installed?

$ python --version
Python 3.6.4

如果仍然看到2.7,请确保在 PATH/usr/local/bin/中优先于/usr/bin/

也许它必须对 PATH做些什么??有人可以用简单的英语解释确切的 PATH 是什么,以及在运行时如何将默认的python设置为python3.终端中的 python --version 吗?

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?

推荐答案

可能最安全,最简单的方法是使用酿造,然后只需修改您的PATH:

Probably the safest and easy way is to use brew and then just modify your PATH:

第一次更新brew:

brew update

接下来安装python:

Next install python:

brew install python

这将安装并将python3符号链接到python,有关更多详细信息,请执行以下操作:

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

brew info python

注意事项:

==> 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

然后将其添加到您的路径/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

PATH的顺序很重要,比起/usr/bin/python

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

这篇关于在Mac上将python3设置为我的默认python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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