Install of Anaconda Python on Ubuntu involves a series of steps that include setting up the Anaconda environment.
As a part of our Server Management Services, we help our Customers with software installations regularly.
Let us today discuss the steps to install Anaconda Python on Ubuntu.
Installing Anaconda
To install Anaconda, we need to download the latest Anaconda installer bash script from the official website.
For this, change to the /tmp directory on the server and use curl to download the link that you copied from the Anaconda website:
$ curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
Now verify the data integrity of the installer with cryptographic hash verification using the command below:
$ sha256sum Anaconda3-2019.03-Linux-x86_64.sh
Check the output against the hashes available at the Anaconda with Python 3 on the 64-bit Linux page for the appropriate Anaconda version. As long as the output matches the hash displayed in the sha2561 row, we are good to go.
Now we can run the script to start the installation:
$ bash Anaconda3-2019.03-Linux-x86_64.sh
This installation script prompts to choose the location of the installation. We can press ENTER to accept the default location, or specify a different location to modify it.
Once the installation is complete, you will receive the following output that “installation finished”. It also asks if we want to prepend the Anaconda3 install location the .bashrc file.
Now activate the installation by sourcing the ~/.bashrc file:
$ source ~/.bashrc
Now that Anaconda is installed, we can go on to setting up Anaconda environments.
Setting Up Anaconda Environments
Anaconda virtual environments allow us to keep projects organized by Python versions and packages needed. For each Anaconda environment, we can specify which version of Python to use and can keep all of the 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$"
We will receive output with the different versions of Python that we can target.
To create an environment using the most recent version of Python 3, use the command below. Here my_env is the environment name:
$ conda create --name my_env python=3
The conda utility will now fetch the packages for the environment and let us know when it is complete. We can activate the new environment by typing the following:
$ conda activate my_env
As the environment is active now, the command prompt prefix will change to include the environment name. Now to verify the python version, use the command below:
(my_env) bob@ubuntu:~$ python --version
Python 3.7 :: Anaconda, Inc.
Now, to deactivate the Anaconda environment, use the command below:
(my_env) bob@ubuntu:~$ conda deactivate
Further, to update the version of Python along the same branch within a respective environment with the following command:
(my_env) bob@ubuntu:~$ conda update python
To update to a more specific version of Python, we can pass that to the python argument, as in python=3.3.2.
Also, we can inspect all of the environments set up with this command:
$ conda info --envs
Each environment we create with conda comes with several default packages like the ones given below:
- openssl
- pip
- python
- readline
- setuptools
- sqlite
- tk
- wheel
- xz
- zlib
Further, we can add additional packages, such as NumPy for example, with the following command:
$ conda install --name my_env35 numpy
To add a package at the time of creating the environment, use the command below(Here NumPy is the package that needs to be added):
$ conda create --name my_env python=3 numpy
To remove an environment, use the command below:
$ conda remove --name my_env35 --all
Updating Anaconda
It is important to keep Anaconda up to date to work with the latest package releases. To do this, we should first update the conda utility:
$ conda update conda
Once the update of conda is complete, we can update the Anaconda distribution:
$ conda update anaconda
This will ensure that you are using the latest releases of conda and Anaconda.
Uninstalling Anaconda
To uninstall anaconda start with the anaconda-clean module, which will remove configuration files during the uninstall process.
$ conda install anaconda-clean
Once installed, we can run the following command:
anaconda-clean
This will also create a backup folder called .anaconda_backup in the home directory. We can now remove the entire Anaconda directory by entering the following command:
$ rm -rf ~/anaconda3
Finally, we can remove the PATH line from the .bashrc file that Anaconda added. To do so, first, open this file with a text editor and then scroll down to the end of the file. Now, Delete or comment out the export PATH line.
Anaconda is now removed from your server.
[Need any further assistance to install Anaconda Python on Ubuntu? – We’re available 24*7]
Conclusion
In short, install of Anaconda Python on Ubuntu involves a series of steps to install and setup the Anaconda environment. Today, we saw how our Support Engineers install, setup, update, and uninstall Anaconda.
0 Comments