Debian

Install Anaconda Python on Debian 10

Anaconda is a Python distribution designed for data science, machine learning, deep learning etc.  In this article, I am going to show you how to install Anaconda Python on Debian 10. So, let’s get started.

Downloading Anaconda Python:

Anaconda Python is not available in the official package repository of Debian 10. But you can easily download it from the official website of Anaconda Python and install it on Debian 10.

First, visit the official website of Anaconda Python and click on Download.

Now, click on Download.

Python 2 and Python 3 versions of Anaconda Python distribution is available for download.

Click on the Download button of the Anaconda Python version that you want to download.

In this article, I will show you how to install Anaconda Python 3. But the process is the same for Anaconda Python 2.

Once you click on the Download button, your browser should prompt you to save the Anaconda Python installer. Select Save File and click on OK.

Your browser should start installing Anaconda Python installer. It may take a while to complete.

Installing Anaconda Python:

Once the download is complete, navigate to the ~/Downloads directory as follows:

$ cd ~/Downloads

Anaconda Python installer that you’ve downloaded should be there. In my case the filename is Anaconda3-2019.10-Linux-x86_64.sh

$ ls -lh

Now, add execute permission to the Anaconda Python installer with the following command:

$ chmod +x Anaconda3-2019.10-Linux-x86_64.sh

Now, run the Anaconda Python installer as follows:

$ ./Anaconda3-2019.10-Linux-x86_64.sh

NOTE: If you want to install Anaconda Python in a location other than your HOME directory, you must run Anaconda Python installer with sudo or as root user.

$ sudo ./Anaconda3-2019.10-Linux-x86_64.sh

Anaconda Python installer should start. Press <Enter> to continue.

Anaconda Python installer should show you the Anaconda End User License Agreement (EULA).

Press <Space Bar> a few times to go the end of the license agreement.

Now, type in yes and press <Enter> to accept the license agreement.

Now, type in a location where you want to install Anaconda Python and press <Enter>. The default installation location for Anaconda Python 3 is ~/anaconda3.

NOTE: If you want to install Anaconda Python somewhere such as /opt/anaconda3 or /usr/apps/anaconda3, you will have to run Anaconda Python installer with sudo or as root user.

Anaconda Python installer should start installing Anaconda Python.

Anaconda Python is being installed.

At the end of the installation process, you will be asked whether you want to automatically load Anaconda Python when you open a new Terminal app.

If you want Anaconda Python to automatically load when you open a new Terminal app, then type in yes and press <Enter>. Otherwise, just press <Enter>.

Anaconda Python should be installed.

Once the installation is complete, run the following command to verify whether Anaconda Python was installed correctly.

$ conda --version

The command above should print the version information of Anaconda Python as you can see in the screenshot below.

Activating Anaconda Python Environment Manually:

You can activate Anaconda Python when you need it with the following command:

$ conda activate

Anaconda Python should be activated. Once Anaconda Python is activated, it should change the Terminal prompt as you can see in the screenshot below.

To verify whether Anaconda version of Python is used, start the Python command line interpreter as follows:

$ python3

NOTE: For Anaconda Python 2, the command to start the Python command line interpreter is python.

$ python

It should print Anaconda, Inc. on linux as you can see in the screenshot below. It means, Anaconda version of Python is used.

Now, type in exit() and press <Enter> or press <Ctrl> + D to exit out of the Python command line interpreter.

Once you’re done working with Anaconda Python, you can deactivate it with the following command:

$ conda deactivate

The Terminal prompt should change back to the default.

Now, if you start the Python interpreter again, it should be the one provided by your Linux distribution as you can see in the screenshot below.

Activating Anaconda Python Environment Automatically:

If you want to activate Anaconda Python automatically when you open a new Terminal, then run the following command:

$ conda config --set auto_activate_base true

Now, close the Terminal and open a new one. Anaconda Python should be activated automatically by default.

If you don’t want to activate Anaconda Python automatically anymore, then run the following command to disable auto activation:

$ conda config --set auto_activate_base false

Anaconda Python won’t automatically activate anymore.

Running Python Programs with Anaconda Python:

In this section, I will write a very simple Python 3 script and run it with Anaconda Python 3.

I have created a Python 3 script file hello.py in the ~/codes directory.

The contents of the hello.py Python 3 script is as follows:

#!/bin/env python3
number1 = 2
number2 = 6
sum = number1 + number2
print("Hello World from LinuxHint!\n")
print("Did you know?")
print("%d + %d = %d" %(number1, number2, sum))

When you want to run your Python 3 script with Anaconda Python, make sure the first line of the Python 3 script is:

#!/bin/env python3

NOTE: For Anaconda Python 2, the line should be:

#!/bin/env python

This will find the Python interpreter using the environment variables. So, when you activate Anaconda python, it will use Anaconda Python. Otherwise, it will use the Linux distribution provided version of the Python interpreter.

Now, activate Anaconda Python as follows:

$ conda activate

Now, navigate to the ~/codes directory as follows:

$ cd ~/codes

The hellop.py Python 3 script should be there.

$ ls -lh

Now, you can run the Python 3 script hello.py as follows:

$ python3 hello.py

The desired output should be printed.

You can also run the script as any normal executable file (without specifying what Python interpreter to use).

To do that, add executable permission to the hello.py Python 3 script as follows:

$ chmod +x hello.py

Now, run the Python 3 script with Anaconda Python as follows:

$ ./hello.py

The desired output should be printed.

Finally, deactivate Anaconda Python as follows:

$ conda deactivate

So, that’s how you install Anaconda Python on Debian 10. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.