[英]Will installing Anaconda3 change Mac OS X default Python version to 3.4?
I'm planning to install Anaconda3 for Python 3.4. 我打算为Python 3.4安装Anaconda3。 Since by default, Mac OS X uses Python2, will install Anaconda3 change the default Python version for the system?
由于默认情况下,Mac OS X使用Python2,因此安装Anaconda3会更改系统的默认Python版本吗? I don't want that to happen since Python3 can break backwards compatibility.
我不希望这种情况发生,因为Python3会破坏向后兼容性。 If it does change the default Python version, how can I avoid that?
如果确实更改了默认的Python版本,该如何避免呢?
Apple has a built-in system for managing multiple versions of software, and switching between them. Apple有一个内置系统,用于管理软件的多个版本,并在它们之间进行切换。 But you don't even need to worry about that, because Anaconda installations are self-contained: Everything lives under the top Anaconda installation directory (probably
/Applications/anaconda
). 但是您甚至不必担心,因为Anaconda安装是独立的:所有内容都位于Anaconda顶级安装目录(可能是
/Applications/anaconda
)下。 The only effect outside this directory is that during installation, Anaconda will offer to modify the PATH
variable in your .bashrc
. 此目录之外的唯一影响是,在安装过程中,Anaconda将提供修改
.bashrc
的PATH
变量的功能。 If you agree, it will add one line at the end of your .bashrc
, something like this: 如果你同意,它会在你的末尾添加一行
.bashrc
,这样的事情:
PATH="/Applications/anaconda/bin:$PATH"
As you can see, Anaconda puts itself first in the system path. 如您所见,Anaconda将自己置于系统路径的首位 。 This means that typing
python
at the shell prompt will launch python 3, which may not be what you want. 这意味着在shell提示符下键入
python
将启动python 3,这可能不是您想要的。 I run Anaconda 3.4 like this and have had absolutely no problems with my system, but I did need to modify my own executable python2 scripts that launched python like this: 我这样运行Anaconda 3.4,并且系统完全没有问题,但是我确实需要修改自己的可执行python2脚本,如下所示启动python:
#!/usr/bin/env python
This is a nice way to find python wherever it is, but in this case it will find python 3-- oops! 这是在任何地方都可以找到python的好方法,但是在这种情况下,它将找到python 3--oops! Changing the above to
#!/usr/bin/python
or to #!/usr/bin/env python2
ensures that they continue to work correctly. 将以上内容更改为
#!/usr/bin/python
或#!/usr/bin/env python2
可以确保它们继续正常工作。 In my experience this was not necessary with any of the system's own scripts; 以我的经验,这对于系统自己的任何脚本都是没有必要的。 everything is already set up to find the right python.
一切都已经建立,可以找到正确的python。
Alternative 1: You could decline the PATH modification, and use Anaconda via the launcher. 选择1:您可以拒绝PATH修改,并通过启动器使用Anaconda。 In that case there is no change to the rest of your execution environment.
在这种情况下,有你的执行环境的其余部分没有变化。 The launcher will start a special bash prompt with the anaconda environment activated, but execution in normal shells is completely unaffected.
启动器将在anaconda环境被激活的情况下启动特殊的bash提示符,但是在普通shell中执行完全不受影响。 If you will continue to program a lot in python 2, this may be for you.
如果您将继续在python 2中进行大量编程,那么这可能适合您。
Alternative 2: A minimal-impact alternative is to put the anaconda directory last in your path: 替代方法2:一种影响最小的替代方法是将anaconda目录放在路径的最后 :
PATH="$PATH:/Applications/anaconda/bin"
This ensures that non-anaconda binaries take precedence over anaconda, so python
will start good old /usr/bin/python
(that is, python 2). 这样可以确保非anaconda二进制文件优先于anaconda,因此
python
将启动旧的/usr/bin/python
(即python 2)。 You can start anaconda's variant by typing python3
, idle3
, etc. I did not have IPython before I installed anaconda, so typing ipython
finds the anaconda version. 您可以通过键入
python3
, idle3
等来启动anaconda的变体。在安装anaconda之前,我没有IPython,因此键入ipython
找到anaconda版本。
不,它不会,您可以安装多个python,一旦不删除系统python或手动更改默认值,就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.