【ML_Preparation 2 】Anaconda 詳解及多 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/

 

-----------本文系轉載,已備後用,原作者信息如下---------- 
作者:dale丶無雙 
來源:CSDN 
原文:https://blog.csdn.net/weixin_39278265/article/details/82982937 

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