Python 101 (1) Env Setup

setting up a python conda environment

Setting Up a Python Environment with Conda

Conda is a powerful package management and environment management system that makes it easy to manage Python environments and dependencies. Before we dive into using Conda, let’s understand the concept of a Python virtual environment.

What is a Python Virtual Environment?

A Python virtual environment is a self-contained directory that contains its own Python interpreter and library installations. It allows you to isolate projects and their dependencies, preventing conflicts between different projects that may require different versions of packages.

Why Use Conda?

Conda provides a convenient way to create, manage, and switch between Python environments. Here are some reasons why Conda is preferred:

Step 1 - Install Conda

If you haven’t installed Conda yet, you can download and install it by following the instructions on the official Conda website.

Step 2 - Open a Terminal or Command Prompt

Open a terminal or command prompt on your system. This is where you will enter the Conda commands to create and manage Python environments.

Step 3 - Create a New Python Environment

To create a new Python environment, use the following command:

conda create --name myenv python=3.8

Step 4 - Activate the Environment

Activate the newly created environment using the following command:

conda activate myenv

Step 5 - Install Packages (e.g., PyTorch)

Install packages into the newly created environment using, for example, the following command:

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

Step 6 - View Environments

See all your environments using the following command:

conda info --envs

Step 7 - Deactivate Environment

When you’re done working in the environment, deactivate it using the following command:

conda deactivate

That’s it! You’ve now covered the steps to activate, install packages, view/manage environments, and deactivate a Python environment using Conda. Feel free to use and customize this guide based on your specific needs.