How To Install the Anaconda Python Distribution on Debian 9

Introduction

Anaconda is an open-source package manager, environment manager, and distribution of the Python and R programming languages. Designed for data science and machine learning workflows, it is commonly used for large-scale data processing, scientific computing, and predictive analytics.

Available in both free and paid enterprise versions, Anaconda offers a collection of over 1,000 data science packages. The Anaconda distribution ships with the conda command-line utility. You can learn more about Anaconda and conda by reading the official Anaconda Documentation.

This tutorial will guide you through installing the Python 3 version of Anaconda on a Debian 9 server.

Prerequisites

Before you begin with this guide, you should have a non-root user with sudo privileges set up on your server.

You can achieve this prerequisite by completing our Debian 9 initial server setup guide.

Installing Anaconda

The best way to install Anaconda is to download the latest Anaconda installer bash script, verify it, and then run it.

Find the latest version of Anaconda for Python 3 at the Downloads page accessible via the Anaconda home page. At the time of writing, the latest version is 5.2, but you should use a later stable version if it is available.

Next, change to the /tmp directory on your server. This is a good directory to download ephemeral items, like the Anaconda bash script, which we won't need after running it.

cd /tmp

We’ll use the curl command-line tool to download the script. Install curl:

sudo apt install curl

Now, use curl to download the link that you copied from the Anaconda website:

curl -O https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh

We can now verify the data integrity of the installer with cryptographic hash verification through the SHA-256 checksum. We’ll use the sha256sum command along with the filename of the script:

sha256sum Anaconda3-5.2.0-Linux-x86_64.sh

You’ll receive output that looks similar to this:

Output09f53738b0cd3bb96f5b1bac488e5528df9906be2480fe61df40e0e0d19e3d48  Anaconda3-5.2.0-Linux-x86_64.sh

You should check the output against the hashes available at the Anaconda with Python 3 on 64-bit Linux page for your appropriate Anaconda version. As long as your output matches the hash displayed in the sha2561 row, you’re good to go.

Now we can run the script:

bash Anaconda3-5.2.0-Linux-x86_64.sh

You’ll receive the following output:

Output
Welcome to Anaconda3 5.2.0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 

Press ENTER to continue and then press ENTER to read through the license. Once you’re done reading the license, you’ll be prompted to approve the license terms:

OutputDo you approve the license terms? [yes|no]

As long as you agree, type yes.

At this point, you’ll be prompted to choose the location of the installation. You can press ENTER to accept the default location, or specify a different location to modify it.

OutputAnaconda3 will now be installed into this location:
/home/sammy/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/sammy/anaconda3] >>> 

The installation process will continue. Note that it may take some time.

Once installation is complete, you’ll receive the following output:

Output...
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/sammy/.bashrc ? [yes|no]
[no] >>> 

Type yes so that you can use the conda command. You’ll receive the following output next:

OutputAppending source /home/sammy/anaconda3/bin/activate to /home/sammy/.bashrc
A backup will be made to: /home/sammy/.bashrc-anaconda3.bak
...

Finally, you’ll receive the following prompt regarding whether or not you would like to download Visual Studio Code (or VSCode), a free and open-source editor for code developed by Microsoft that can run on Linux. You can learn more about the editor on the official Visual Studio Code website.

At this point, you can decide whether or not to download the editor now by typing yes or no.

Anaconda is partnered with Microsoft! Microsoft VSCode is a streamlined
code editor with support for development operations like debugging, task
running and version control.

To install Visual Studio Code, you will need:
  - Administrator Privileges
  - Internet connectivity

Visual Studio Code License: https://code.visualstudio.com/license

Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
>>> 

In order to activate the installation, you should source the ~/.bashrc file:

source ~/.bashrc

Once you have done that, you can verify your install by making use of the conda command, for example with list:

conda list

You’ll receive output of all the packages you have available through the Anaconda installation:

Output# packages in environment at /home/sammy/anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py36he11e457_0  
alabaster                 0.7.10           py36h306e16b_0  
anaconda                  5.2.0                    py36_3  
...

Now that Anaconda is installed, we can go on to setting up Anaconda environments.

Setting Up Anaconda Environments

Anaconda virtual environments allow you to keep projects organized by Python versions and packages needed. For each Anaconda environment you set up, you can specify which version of Python to use and can keep all of your related programming files together within that directory.

First, we can check to see which versions of Python are available for us to use:

conda search "^python$"

You’ll receive output with the different versions of Python that you can target, including both Python 3 and Python 2 versions. Since we are using the Anaconda with Python 3 in this tutorial, you will have access only to the Python 3 versions of packages.

Let’s create an environment using the most recent version of Python 3. We can achieve this by assigning version 3 to the python argument. We’ll call the environment my_env, but you’ll likely want to use a more descriptive name for your environment especially if you are using environments to access more than one version of Python.

conda create --name my_env python=3

We’ll receive output with information about what is downloaded and which packages will be installed, and then be prompted to proceed with y or n. As long as you agree, type y.

The conda utility will now fetch the packages for the environment and let you know when it’s complete.

You can activate your new environment by typing the following:

source activate my_env

With your environment activated, your command prompt prefix will change:

Within the environment, you can verify that you’re using the version of Python that you had intended to use:

 python --version

OutputPython 3.7.0 :: Anaconda, Inc.

When you’re ready to deactivate your Anaconda environment, you can do so by typing:

source deactivate

Note that you can replace the word source with . to achieve the same results.

To target a more specific version of Python, you can pass a specific version to the python argument, like 3.5, for example:

conda create -n my_env35 python=3.5

You can update your version of Python along the same branch (as in updating Python 3.5.1 to Python 3.5.2) within a respective environment with the following command:

conda update python

If you would like to target a more specific version of Python, you can pass that to the python argument, as in python=3.3.2.

You can inspect all of the environments you have set up with this command:

conda info --envs

Output# conda environments:
#
base                  *  /home/sammy/anaconda3
my_env                   /home/sammy/anaconda3/envs/my_env
my_env35                 /home/sammy/anaconda3/envs/my_env35

The asterisk indicates the current active environment.

Each environment you create with conda create will come with several default packages:

  • openssl
  • pip
  • python
  • readline
  • setuptools
  • sqlite
  • tk
  • wheel
  • xz
  • zlib

You can add additional packages, such as numpy for example, with the following command:

conda install --name my_env35 numpy

If you know you would like a numpy environment upon creation, you can target it in your conda createcommand:

conda create --name my_env python=3 numpy

If you are no longer working on a specific project and have no further need for the associated environment, you can remove it. To do so, type the following:

conda remove --name my_env35 --all

Now, when you type the conda info --envs command, the environment that you removed will no longer be listed.

Updating Anaconda

You should regularly ensure that Anaconda is up-to-date so that you are working with all the latest package releases.

To do this, you should first update the conda utility:

conda update conda

When prompted to do so, type y to proceed with the update.

Once the update of conda is complete, you can update the Anaconda distribution:

conda update anaconda

Again when prompted to do so, type y to proceed.

This will ensure that you are using the latest releases of conda and Anaconda.

Uninstalling Anaconda

If you are no longer using Anaconda and find that you need to uninstall it, you should start with the anaconda-clean module, which will remove configuration files for when you uninstall Anaconda.

conda install anaconda-clean

Type y when prompted to do so.

Once it is installed, you can run the following command. You will be prompted to answer y before deleting each one. If you would prefer not to be prompted, add --yes to the end of your command:

anaconda-clean

This will also create a backup folder called .anaconda_backup in your home directory:

OutputBackup directory: /home/sammy/.anaconda_backup/2018-09-06T183049

You can now remove your entire Anaconda directory by entering the following command:

rm -rf ~/anaconda3

Finally, you can remove the PATH line from your .bashrc file that Anaconda added. To do so, first open a text editor such as nano:

nano ~/.bashrc

Then scroll down to the end of the file (if this is a recent install) or type CTRL + W to search for Anaconda. Delete or comment out the export PATH line:

/home/sammy/.bashrc

...
# added by Anaconda3 installer
export PATH="/home/sammy/anaconda3/bin:$PATH"

When you’re done editing the file, type CTRL + X to exit and y to save changes.

Anaconda is now removed from your server.

Conclusion

This tutorial walked you through the installation of Anaconda, working with the conda command-line utility, setting up environments, updating Anaconda, and deleting Anaconda if you no longer need it.

You can use Anaconda to help you manage workloads for data science, scientific computing, analytics, and large-scale data processing. From here, you can check out our tutorials on data analysis and machine learning to learn more about various tools available to use and projects that you can do.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,260评论 0 10
  • 你走了已经十四年了。 时间过得真快。 你走的那年,我才11岁。喜欢的都是最新的流行歌,对你一无所知。 你走的轰轰烈...
    乱弹阿琳阅读 839评论 4 10
  • 在人生的道路上,家长教导我们,人不能没有追求,老师教导我们,从小就要立志。每个人都有梦想,每个人的梦想都是...
    _南茗_阅读 410评论 0 1
  • 二十年前,唐伯虎上京赶考,落得一个悲惨的下场,好歹出了狱,他本想振作精神,回家过点平静的日子,可当他返乡后,才发现...
    异色瞳的忧伤阅读 1,251评论 0 0
  • 小A的烦恼 我从来都没有认为自己是一个天赋异禀的人,甚至,连个普通人都算不上,以至于,我对于许多事情的看法,可以说...
    CRAZIER姜阅读 466评论 0 0