详解Anaconda + 如何在Anaconda上更换python版本「建议收藏」

详解Anaconda + 如何在Anaconda上更换python版本「建议收藏」本文旨在详细介绍Anaconda以及如何在Anaconda上更换python版本。

大家好,又见面了,我是你们的朋友全栈君。

前言

本文旨在详细介绍Anaconda 以及 如何在Anaconda上更换python版本。

备注: 根据读者建议,这里明确如下:
标题中的“在Anaconda上更换python版本”实际上是指:通过创建新的环境,得到自己想要的Python版本环境,而非在现有的环境中修改Python版本(这个应该也比较简单,参考我另外一篇博客:在当前conda env(conda环境)内修改Python的版本(升级或者降级),当然,仅供参考)。

1 Anaconda具体是用来干什么的

根据其主页介绍:https://www.anaconda.com/what-is-anaconda/

Anaconda – The Most Popular Python Data Science Platform
Anaconda Distribution – With over 6 million users, the open source Anaconda Distribution is the fastest and easiest way to do Python and R data science and machine learning on Linux, Windows, and Mac OS X. It’s the industry standard for developing, testing, and training on a single machine.

Anaconda是最流行的数据科学平台。但这个还不能解释性质上的问题。

根据wiki百科,https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)

Anaconda is a free and open source[5] distribution of the Python and R programming languages for data science and machine learning related applications (large-scale data processing, predictive analytics, scientific computing), that aims to simplify package management and deployment. Package versions are managed by the package management system conda.[6] The Anaconda distribution is used by over 6 million users, and it includes more than 250 popular data science packages suitable for Windows, Linux, and MacOS.[5]

这下就更清楚了,Anaconda是一个免费,开源的针对数据科学处理和机器学习相关应用的Python和R语言的发行版。Anaconda发行版被6百万人使用,而且它包括了超过250个流行的数据科学处理包(适用于各个平台)。

Anaconda distribution comes with more than 1,000 data packages as well as the Conda package and virtual environment manager, called Anaconda Navigator [7], so it eliminates the need to learn to install each library independently.

Anaconda = 超过1000个数据包 + Conda package + virtual environment manager (即 Anaconda Navigator)。
这样的话,anaconda在管理包上是很方便的。

The open source data packages can be individually installed from the Anaconda repository [8] with the conda install command or using the pip install command that is installed with Anaconda. Pip packages provide many of the features of conda packages and in most cases they can work together.

原来pip和conda可以work together。

The default installation of Anaconda2 includes Python 2.7 and Anaconda3 includes Python 3.7. However, you can create new environments that include any version of Python packaged with conda [10].

虽然默认安装,但是我们可以用conda来创造python版本新环境。

对anaconda navigator的介绍:

Anaconda Navigator is a desktop graphical user interface (GUI) included in Anaconda distribution that allows users to launch applications and manage conda packages, environments and channels without using command-line commands. Navigator can search for packages on Anaconda Cloud or in a local Anaconda Repository, install them in an environment, run the packages and update them. It is available for Windows, macOS and Linux.

The following applications are available by default in Navigator [11]:
JupyterLab
Jupyter Notebook
QtConsole
Spyder
Glueviz
Orange
Rstudio
Visual Studio Code

原来anaconda navigator是干这个的,用来管理包,安装、运行应用。

对conda的介绍:

Conda is an open source,[12] cross-platform,[13] language-agnostic[14] package manager and environment management system[15][16][17] that installs, runs, and updates packages and their dependencies.[12] It was created for Python programs, but it can package and distribute software for any language (e.g., R), including multi-language projects.[14] The Conda package and environment manager is included in all versions of Anaconda, Miniconda,[18] and Anaconda Repository.[8]

conda最开始用来配置python,但是实际上可以配置任何语言的包。很酷。

关于anaconda cloud的介绍:

Anaconda Cloud is a package management service by Anaconda where you can find, access, store and share public and private notebooks, environments, and conda and PyPI packages. Cloud hosts useful Python packages, notebooks and environments for a wide variety of applications. You do not need to log in or to have a Cloud account, to search for public packages, download and install them.

You can build new packages using the Anaconda Client command line interface (CLI), then manually or automatically upload the packages to Cloud.

维基百科是真的给力,通过上述介绍,anaconda,conda,anaconda navigator的概念和作用就很明了了。

2 conda,pip,anaconda,miniconda的区别

网页https://www.quora.com/What-is-the-comparison-among-conda-vs-pip-vs-anaconda 很好的回答了四种概念的区别:

1)conda:

conda is a package management tool for installing scientific and analytical computing packages, which may be written in Python or other programming languages.

conda also creates a virtual environment, like python-virtualenv does.

2)anaconda:

conda is the package manager of Anaconda. Anaconda is a free Python distribution provided by Continuum Analytics, which includes over 195 of the most popular Python packages for science, math, engineering and data analysis.

(Anaconda is a set of about a hundred packages including conda, numpy, scipy, ipython notebook, and so on.)

3)miniconda:

You installed Miniconda, which is a smaller alternative to Anaconda that is just conda and its dependencies (as opposed to Anaconda, which is conda and a bunch of other packages like numpy, scipy, ipython notebook, etc.). Once you have Miniconda, you can easily install Anaconda into it with conda install anaconda. )

4)pip and conda:

pip is a general purpose Python package installer. In addition, python-pip and python3-pip are in the default Ubuntu repositories. In most cases you would choose pip instead of conda if you want to install a Python package management application. To create a Python virtual environment without installing conda, you can install python-virtualenv from the Ubuntu Software Center.

pip and conda use different packaging formats so they do not operate interchangeably, but you can use both tools side by side.

看完这些描述,我总结一下:
conda是anaconda下面的一个包,也是一个包管理工具。anaconda则是一个python发行版本,包含有conda在内的各种包。miniconda就是只包含conda和conda的依赖,对于其他包,可以用conda装。pip是python 包下载管理工具,conda的话不仅是python 包下载管理工具,还可以下载其他语言的包(比如R语言),当然conda和pip是可以一起用的。

原来如此。想知道更多关于conda的,请见[4]

3 anaconda中的几个应用介绍

打开anaconda navigator,发现有一些应用:



在这里插入图片描述

根据网页https://www.jianshu.com/p/eaee1fadc1e9 介绍:
Anaconda Navigtor :用于管理工具包和环境的图形用户界面,后续涉及的众多管理命令也可以在 Navigator 中手工实现。
Jupyter notebook :基于web的交互式计算环境,可以编辑易于人们阅读的文档,用于展示数据分析的过程。
qtconsole :一个可执行 IPython 的仿终端图形界面程序,相比 Python Shell 界面,qtconsole 可以直接显示代码生成的图形,实现多行代码输入执行,以及内置许多有用的功能和函数。
spyder :一个使用Python语言、跨平台的、科学运算集成开发环境。

4 如何在anaconda下改变python的版本

根据网页:http://python.jobbole.com/87522/

使用以下命令创建新环境:
conda create -n env_name list of packages

其中 -n 代表 name,env_name 是需要创建的环境名称,list of packages 则是列出在新环境中需要安装的工具包。

比如我现在的python版本是3.7,但是我想安装一个python 3.6的环境,则在anaconda prompt输入:
conda create -n py36 python=3.6

控制台会输出:



在这里插入图片描述

以及

# To activate this environment, use
#
#     $ conda activate py36
#
# To deactivate an active environment, use
#
#     $ conda deactivate

还是很酷很方便的。

现在激活这个新配置的环境:conda activate py36
输入python –version,可以看到:

(py36) C:\Users\dehen>python --version
Python 3.6.6 :: Anaconda, Inc.

(py36) C:\Users\dehen>

这时候打开anaconda navigator,发现多出来一个环境选择,太酷了。
在这里插入图片描述

这时候install 这个spyder就可以运行3.6版本下的程序了。

在这里插入图片描述

索性再配置一个python2.7的新环境:conda create -n py27 python=2.7
很快就显示配置完成并输出提示:

# To activate this environment, use
#
#     $ conda activate py27
#
# To deactivate an active environment, use
#
#     $ conda deactivate

所以,这样看来确实很方便,各个环境互相独立,都放在文件夹 D:\software\anaconda\envs 下:
在这里插入图片描述

还有,如果要删除我们配置的新环境,则:
conda env remove -n env_name

显示所有环境:
conda env list

当分享代码的时候,同时也需要将运行环境分享给大家,执行如下命令可以将当前环境下的 package 信息存入名为 environment 的 YAML 文件中。[6]
conda env export > environment.yaml

同样,当执行他人的代码时,也需要配置相应的环境。这时你可以用对方分享的 YAML 文件来创建一摸一样的运行环境。
conda env create -f environment.yaml

参考文献

[1] what-is-anaconda. https://www.anaconda.com/what-is-anaconda/
[2] Anaconda (Python distribution). https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)
[3] What is the comparison among conda vs pip vs anaconda? https://www.quora.com/What-is-the-comparison-among-conda-vs-pip-vs-anaconda

[4]
中文网页:
Anaconda、Miniconda、Conda、pip的相互关系. http://blog.sina.com.cn/s/blog_8a122dcf0102x9vn.html

原英文网页:
Conda: Myths and Misconceptions. https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/

[5] Anaconda完全入门指南. https://www.jianshu.com/p/eaee1fadc1e9

[6] 致Python初学者:Anaconda入门使用指南. http://python.jobbole.com/87522/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/140081.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(2)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号