Anaconda使用


Anaconda官網:https://www.continuum.io/
Anaconda 提供一個管理工具 conda ,可以把 conda 看作是 pip + virtualenv +PVM (Python Version Manager) + 一些必要的底層庫,也就是一個更完整也更大的集成管理工具。

1. 下載、安裝 Anaconda

如果只想用 conda ,可以下載簡化版的 Miniconda ,需要 Anaconda 可以安裝完全版,一共大概 400 M,用阿里雲服務器從官方網站下載大概要 6 個小時…不過還好清華大學 TUNA 鏡像源 提供了鏡像:

# 下載時要看清楚 Anaconda3 還是 2,對應的是 Python 3.5 和 2.7 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/Anaconda3-2.5.0-Linux-x86_64.sh bash Anaconda3-2.5.0-Linux-x86_64.sh

設定安裝目錄 /home/rainy/.anaconda3 並一路確認,會在 ~/.bashrc 添加環境變量,因為我用的是 zsh ,所以需要在 ~/.zshrc 添加:

# added by Anaconda3 2.5.0 installer
export PATH="/home/rainy/.anaconda3/bin:$PATH" conda --version # conda 3.19.1

2. 創建(clone)新的環境

conda env list
# conda environments: # root * /home/rainy/.anaconda3 conda create --name nb --clone root conda env list # conda environments: # nb /home/rainy/.anaconda3/envs/nb root * /home/rainy/.anaconda3

切換環境:

source activate nb
# discarding /home/rainy/.anaconda3/bin from PATH # prepending /home/rainy/.anaconda3/envs/nb/bin to PATH

此時變成 (nb) $ ,和 virtualenv 一樣,只是在退出時不太一樣:

which python
/home/rainy/.anaconda3/envs/nb/bin/python source deactivate discarding /home/rainy/.anaconda3/envs/nb/bin from PATH

需要重新打開新的窗口才能再切換。現在查看已安裝的 package 列表:

source active nb conda list # packages in environment at /home/rainy/.anaconda3/envs/nb: # abstract-rendering 0.5.1 np110py35_0 alabaster 0.7.7 py35_0 anaconda 2.5.0 np110py35_0 anaconda-client 1.2.2 py35_0 argcomplete 1.0.0 py35_1 astropy 1.1.1 np110py35_0 ...

3. 下載安裝package

Anaconda作為一個工具包集成管理工具,下載python工具包是很方便的,直接敲:

conda install package_name

但是有時候安裝一個工具包(如xmltodict)的時候,在當前的channels中找不到這個包,會提示:

[root@master sbin]$ conda install xmltodict
Fetching package metadata ....... Solving package specifications: . PackageNotFoundError: Package not found: '' Package missing in current linux-64 channels: - xmltodict You can search for packages on anaconda.org with anaconda search -t conda xmltodict

然后你按照提示在anaconda.org中找工具包,

[root@master sbin]$ anaconda search -t conda xmltodict
Using Anaconda API: https://api.anaconda.org Run 'anaconda show <USER/PACKAGE>' to get more details: Packages: Name | Version | Package Types | Platforms ------------------------- | ------ | --------------- | --------------- PinguCarsti/xmltodict | 0.8.3 | conda | linux-64, osx-64 abgreenwell/xmltodict | 0.8.3 | conda | win-64 asmeurer/xmltodict | 0.8.3 | conda | osx-64 : https://github.com/martinblech/xmltodict auto/xmltodict | 0.8.6 | conda | linux-64, linux-32, osx-64 : https://github.com/martinblech/xmltodict bioconda/xmltodict | 0.9.2 | conda | linux-64, osx-64 : Makes working with XML feel like you are working with JSON conda-forge/xmltodict | 0.10.2 | conda | linux-64, win-32, win-64, osx-64 dan_blanchard/xmltodict | 0.8.3 | conda | linux-64 : https://github.com/martinblech/xmltodict davidbgonzalez/xmltodict | 0.9.2 | conda | linux-64, osx-64 : Makes working with XML feel like you are working with JSON derickl/xmltodict | 0.10.2 | conda | osx-64 dimazest/xmltodict | 0.9.2 | conda | linux-64, osx-64 equipoise/xmltodict | 0.9.2 | conda | win-64, osx-64 hargup/xmltodict | | conda | None-None, linux-64 : Makes working with XML feel like you are working with JSON indico/xmltodict | 0.9.2 | conda | linux-64 : Makes working with XML feel like you are working with JSON jacksongs/xmltodict | 0.10.2 | conda | osx-64 kabaka0/xmltodict | 0.9.2 | conda | linux-64 : Makes working with XML feel like you are working with JSON luzazul45/xmltodict | 0.9.2 | conda | win-64 : Makes working with XML feel like you are working with JSON mathieu/xmltodict | 0.10.1 | conda | osx-64 : Makes working with XML feel like you are working with JSON mh00h/xmltodict | 0.9.2 | conda | linux-64 : Makes working with XML feel like you are working with JSON moustik/xmltodict | 0.9.2 | conda | linux-64 russellthomas/xmltodict | 0.9.0 | conda | osx-64 : xmltodict is a simple library that aims at making XML feel like working with JSON xavier/xmltodict | 0.5.1 | conda | linux-64 : https://github.com/martinblech/xmltodict Found 21 packages

我們發現了21個包,現在就選擇一個合適的版本進行安裝,如我選擇這個:

 conda-forge/xmltodict     | 0.10.2 | conda | linux-64, win-32, win-64, osx-64

那么執行下面命令進行安裝即可:

[root@master ~]$ conda install -c https://conda.anaconda.org/conda-forge xmltodict 或者 conda install -c conda-forge xmltodict
詳情參照:http://www.jianshu.com/p/d2e15200ee9b
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM