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