- Published on
Manage Your Python with Anaconda
- Authors
- Name
- Sriharsha Mopidevi
- Github
- @sriharshamvs
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
conda info
Update conda to the current version
conda update conda
Install a package included in Anaconda
conda install PACKAGENAME
Run a package after installation, for example, jupyter*
jupyter
Update any installed program
conda update PACKAGENAME
Command-line help
conda install --help
Managing Environments and Packages
Create a new environment name with a Python version
conda create --name YOUR_ENVIRONMENT_NAME python=PYTHON_VERSION
Example: create a new environment named py37, install Python 3.7
conda create --name py37 python=3.7
Activate the new environment to use it
conda activate YOUR_NEW_ENVIRONMENT
Get a list of all my environments, active the environment is shown with *
conda env list
Deactivate the current environment
conda deactivate
List all packages and versions installed in the active environment
conda list
Switch to a new environment that has a different version of Python
conda activate YOUR_NEW_ENVIRONMENT
Use conda to search for a package
conda search PACKAGENAME
Install a new package in the active environment
conda install PACKAGENAME
Install a package with a specific version number
conda install PACKAGENAME=VERSION_NUMBER
Install a package directly from PyPI into the currently active environment using pip
pip install PACKAGENAME
Remove package using conda
conda remove PACKAGENAME
Remove package using PyPI in the currently active environment
pip uninstall PACKAGENAME
Delete an environment and everything in it
conda env remove --name YOUR_ENVIRONMENT_NAME