Published on

Manage Your Python with Anaconda

Authors

Introduction

I've been using python for a long time now for web development, automation, and data science. Different applications require different python versions and packages. While developing applications, the system sometimes used to throw an error for version incompatibility.

Initially, to solve this I've come across a python module called venv. This creates a virtual environment which is an isolated environment from my base python. But over time, I've come across Anaconda and I've been using it ever since.

What is Anaconda? - Anaconda is a distribution of the Python programming language.

Your next question might be "Why should I get it if I already have Python installed on my system?"

Well, hold your horses. There is a simple answer it makes your life easy in development. Anaconda comes with scientific computing tools and a built-in package management tool (conda) to manage my different python versions and packages.

Installation

Anaconda distribution can be installed on Linux, macOS, and Windows. Download the script/executable file from the anaconda downloads and follow the installation steps. Installation may vary in different operating systems.

Check installation steps for Linux, macOS, and Windows.

Once you have successfully installed it, reboot your system or logout and login.

Getting started with Conda

Conda basics

Verify conda is installed, check the version number

terminal
conda info

Update conda to the current version

terminal
conda update conda

Install a package included in Anaconda

terminal
conda install PACKAGENAME

Run a package after installation, for example, jupyter*

terminal
jupyter

Update any installed program

terminal
conda update PACKAGENAME

Command-line help

terminal
conda install --help

Managing Environments and Packages

Create a new environment name with a Python version

terminal
conda create --name YOUR_ENVIRONMENT_NAME python=PYTHON_VERSION

Example: create a new environment named py37, install Python 3.7

terminal
conda create --name py37 python=3.7

Activate the new environment to use it

terminal
conda activate YOUR_NEW_ENVIRONMENT

Get a list of all my environments, active the environment is shown with *

terminal
conda env list

Deactivate the current environment

terminal
conda deactivate

List all packages and versions installed in the active environment

terminal
conda list

Switch to a new environment that has a different version of Python

terminal
conda activate YOUR_NEW_ENVIRONMENT

Use conda to search for a package

terminal
conda search PACKAGENAME

Install a new package in the active environment

terminal
conda install PACKAGENAME

Install a package with a specific version number

terminal
conda install PACKAGENAME=VERSION_NUMBER

Install a package directly from PyPI into the currently active environment using pip

terminal
pip install PACKAGENAME

Remove package using conda

terminal
conda remove PACKAGENAME

Remove package using PyPI in the currently active environment

terminal
pip uninstall PACKAGENAME

Delete an environment and everything in it

terminal
conda env remove --name YOUR_ENVIRONMENT_NAME