简体   繁体   中英

Will installing Anaconda3 change Mac OS X default Python version to 3.4?

I'm planning to install Anaconda3 for Python 3.4. Since by default, Mac OS X uses Python2, will install Anaconda3 change the default Python version for the system? I don't want that to happen since Python3 can break backwards compatibility. If it does change the default Python version, how can I avoid that?

Apple has a built-in system for managing multiple versions of software, and switching between them. 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 ). The only effect outside this directory is that during installation, Anaconda will offer to modify the PATH variable in your .bashrc . If you agree, it will add one line at the end of your .bashrc , something like this:

PATH="/Applications/anaconda/bin:$PATH"

As you can see, Anaconda puts itself first in the system path. This means that typing python at the shell prompt will launch python 3, which may not be what you want. 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:

#!/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! Changing the above to #!/usr/bin/python or to #!/usr/bin/env python2 ensures that they continue to work correctly. 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.

Alternative 1: You could decline the PATH modification, and use Anaconda via the launcher. 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. If you will continue to program a lot in python 2, this may be for you.

Alternative 2: A minimal-impact alternative is to put the anaconda directory last in your path:

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). 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.

不,它不会,您可以安装多个python,一旦不删除系统python或手动更改默认值,就可以了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM