[Python]在Anaconda中配置多版本Python(Multi-version Python Configuration)

Python很恼人的拥有2和3两个大版本,左手情怀,右手梦想。

因为Tensorflow只支持python3以及python3毕竟是大势所趋,在机器学习的课程或应用中往往采用python3作为应用语言(当然GraphLab是支持python2的)。而很多python的传统应用或较早的git项目中,python2更为常见。因此本文讨论该如何在Anaconda中配置与切换多版本Python。

本文默认是采用Anaconda进行Python的安装和配置,毕竟当前Anaconda比PIP要便捷的多,也更加普遍。关于如何使用Anaconda安装Python本文不再赘述。可以去其官网上下载并配置,上面有很详细的教程。https://www.anaconda.com/download/  当然百度Google也都可以,过程便捷迅速相当无脑。

在安装好后,可以在cmd(Windows)/command(Linux/Unix/Macintosh)中输入python --version查看当前默认python版本。假设当前默认python版本为2.7,而我们想要python3.6,该如何便捷的配置环境呢?

过程非常简单。

Notice:如果是在大陆地区,建议添加清华镜像,下载速度上升几个台阶。在cmd/command中输入

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --set show_channel_urls yes

conda config --remove channels defaults


1. 下载

conda create --name python36 python=3.6

【注:“python36”是环境名,可以任起,比如“Hahaha”之类,随便。“3.6”为想要安装的python版本,想装python2就改成“2.7”就行】

2.激活

activate python36 (Windows)

source activate python36 (Linux/Unix/Mac)


好的结束了就这么简单。

之后想用什么python版本时直接activate就好。卸载某版本命令为 conda remove --name python36 --all, 同理python36是你之前起的环境名。


当然别忘了在新的python环境名中把该装的包装一装,比如tensorflow啊numpy啊什么的

在activate的版本中:

conda install tensorflow

conda install numpy

......


以及IDE,如果需要,要重新装一下对应版本的。

在activate的版本中:

conda install jupyter notebook

conda install spyder

.......


就酱。


Python has two big version: python2 and python3 and both have great practical scenerios.

This article talks about how to download and configure Python version.


I suppose that your initial configuration is based on Anaconda, as it is much more convenient and widespread than customed PIP. How to install Python with Anaconda will not be mentioned in this article. If you want to know, go to Anaconda website(https://www.anaconda.com/download/), which contains all the sources and tutorials you need. The process is very easy.


With installed Python and Anaconda, we can use "python --version" on cmd(Windows)/command(Linux/Unix/Macintosh) to see the default python version in the computer.

Supposing that the default version is 2.7, while we want Python3.6, how can we solve this problem?


Notice that if you are on Mainland, China, using Tsinghua Mirror Sever would speed up much. Just input these in your cmd/command:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --set show_channel_urls yes

conda config --remove channels defaults


1.Download

conda create --name python36 python=3.6

[Notice that the "python36" is the enviroment name, you can change it to any name you like. "3.6"stands for the python version you want. If you desire for Python2.7, just change it to "2.7"]


2.Activation

activate python36 (Windows)

source activate python36 (Linux/Unix/Mac)


Done. Very easy.

That's all. And any time you want to use a certain version , just activate it. If you want to uninstall a version, use "conda remove --name python36 --all", of course the "python36" is corresponding to the name you set before.


Don't forget those packages,like numpy and tensorflow(which must be used in Python3)

(in your activated Python version)

conda install tensorflow

conda install numpy

......


And those IDEs if you want:

(in your activated Python version)

conda install jupyter notebook

conda install spyder

.......


That's all.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章