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:
Anaconda Python installer that you’ve downloaded should be there. In my case the filename is Anaconda3-2019.10-Linux-x86_64.sh
Now, add execute permission to the Anaconda Python installer with the following command:
Now, run the Anaconda Python installer as follows:
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.
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.
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:
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:
NOTE: For Anaconda Python 2, the command to start the Python command line interpreter is 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:
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:
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:
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:
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:
NOTE: For Anaconda Python 2, the line should be:
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:
Now, navigate to the ~/codes directory as follows:
The hellop.py Python 3 script should be there.
Now, you can run the Python 3 script hello.py as follows:
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:
Now, run the Python 3 script with Anaconda Python as follows:
The desired output should be printed.
Finally, deactivate Anaconda Python as follows:
So, that’s how you install Anaconda Python on Debian 10. Thanks for reading this article.