Linux配置Anaconda 4.1.1及相关测试

该博文记录在Ubuntu中配置安装Anaconda的过程

环境介绍

先查看待安装的机器Linux版本,机器号等。

getconf LONG_BIT
# `64` 为64位机器,`32`则为32位机器
cat /proc/version
# `Linux version 4.2.0-c9 (gcc version 4.9.2)`
cat /etc/issue
# `Ubuntu 14.04.3 LTS \n \l`

配置软件介绍

Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python and R and includes over 100 of the most popular Python, R and Scala packages for data science.

Additionally, you’ll have access to over 720 packages that can easily be installed with conda, our renowned package, dependency and environment manager, that is included in Anaconda.

via Anaconda

安装过程

下载对应的Anaconda文件:

wget https://repo.continuum.io/archive/Anaconda2-4.1.1-Linux-x86_64.sh

执行相关文件:

bash Anaconda2-4.1.1-Linux-x86_64.sh

测试过程

该部分主要参看Conda test drive milestones
TIP:我们想要查询某个命令的具体文档时,可以在这个命令之后添加--help查看,例如:

conda update --help

Managing conda

conda既是环境管理器也是包管理器。这个特性使得一些依赖不同python版本的包的管理也不再那么棘手。

Verify that conda is installed

conda --version
# conda 4.1.6

若出现错误信息,可以尝试检查:

  • 是否是安装了Anaconda的环境
  • 在安装之后是否重新启动了终端

Update conda to the current version

conda update conda

conda将比较版本号,并提醒你是否需要更新、更新之后会发生的相关变化。

Managing environments

Create and activate an environment

conda create --name snowflakes biopython

上述命令将创建一个名为biopython的新环境,该环境将安装包biopythonconda默认将环境安装在envs文件夹下(故上述环境对应的文件夹为~/envs/snowflakes),可以通过设置create命令选项进行配置;并且默认也使用与当前python版本相同的版本号。

Activate the new environment

source activate snowflakes
# Windows: `activate snowflakes`

执行上述命令之后,可以通过conda list进行检验;对应的“关”命令为source deactivate

Create a second environment

conda create --name bunnies python=3 astroid babel

上述命令将创建一个名为bunnies的新环境,配置有包astroidbabel,并且python的版本号将变为3。
TIP:最好一次性将需要的包全都说出来,这样conda可以处理一些依赖冲突。

List all environments

conda info --envs
# # conda environments:
# #
# bunnies                  /home/ubuntu/anaconda2/envs/bunnies
# snowflakes               /home/ubuntu/anaconda2/envs/snowflakes
# root                  *  /home/ubuntu/anaconda2

上述命令将列出当前所有的环境,并在当前使用的环境标志上*

Verify environment added
在使用某个环境之后,当前环境将显示在命令行的最前面,例如:

(snowflakes) user:~ $

Deactivate this environment

source deactivate
# Windows: deactivate

上述命令将退出当前环境。

Make an exact copy of an environment

conda create --name flowers --clone snowflakes

上述命令将克隆一个跟snowflakes完全相同的环境出来,可以通过conda info --envs检查是否创建成功。

Delete an environment

conda remove --name flowers --all

上述命令将删除环境flowers,可以通过conda info --envs来检查是否删除成功。

Managing Python

conda将python视为一个包,从而简化了管理。
Check Python versions

conda search --full-name python

该命令是用来查找python的可用版本。使用full-name是为了仅对包名为python的包进行搜索,否则也将会显示包含python的包。

Install a different version of Python

conda create --name python3 python=3

该命令将创建一个python版本为3的环境,名为python3。该环境的激活与关闭的方法与上面所述部分相同。

Verify Python version in new environment

(snowflakes) user:~ $ python --version
# Python 2.7.12 :: Continuum Analytics, Inc.

Managing packages

View a list of packages and versions installed in an environment

conda list

该命令将可以看到当前已安装的包及其版本,当然也可以看到python的版本。

View a list of packages available with the conda install command
conda可以安装的包可参看该链接

Search for a package

conda search beautifulsoup4

该命令用来检查是否有相应的包。

Install a new package

conda install --name bunnies beautifulsoup4

注意,省略namebeautifulsoup4将默认在当前环境中。

Install a package from Anaconda.org
Anaconda.org也提供了一些公共的、甚至私有的包,我们将介绍如何使用它。
我们先在浏览器中输入http://anaconda.org,之后在 “Search Anaconda Cloud”搜素感兴趣的包,并相应的输入安装指令,如下:

conda install -c pandas bottleneck=0.8.0

Install a package with pip
我们也可以借助pip来安装一些包,先是要进入到待安装的环境中,之后执行安装指令:

pip install see  # 安装包see

Removing packages, environments, or conda

Remove a package

conda remove --name bunnies iopro
# 从环境[bunnies]中删除包[iopro]

Remove an environment

conda remove --name snakes --all
# 删除包与删除环境的不同之处在于`all`

Remove conda

rm -rf ~/miniconda  # 删除Miniconda
rm -rf ~/anaconda   # 删除anaconda

Windows环境下可以使用控制面板进行删除。

参考资料

Anaconda
Get Started – Test drive
Conda cheat sheet

    原文作者:大圣软件
    原文地址: https://www.jianshu.com/p/e29b0a8da430
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞