Guide to Virtual Environments with Anaconda

Eduard Balamatiuc
softplus-publication
3 min readSep 11, 2024

Virtual environments are isolated spaces on your computer where you can install and manage specific versions of Python and various packages without affecting your system-wide installations.

In other words, it’s like boxes that help you organize all your clothes (where boxes are the virtual environments and the clothes are your libraries and others)

Anaconda is a powerful distribution of Python and R programming languages for scientific computing, data science, and machine learning. One of its key features is the ability to create and manage virtual environments.

In other words, it’s a tool that can help you manage virtual environments easily.

Why are Anaconda and virtual environments useful?

  • Isolate project dependencies

Every box is dedicated to one thing, basically the running shoes will never get into the wedding related box.

  • Avoid version conflicts between different projects

Let’s say you have two of the same pair of shoes, the first one you always use for running and the second one for going out. Even if it’s the same model, you differentiate them in separate boxes.

  • Easily share and reproduce development environments

Your style is really nice, and when you want to share it, it’s easy, because you have everything separated already in boxes you can just list the clothes from the “going out” box to your friend, and now you have matching outfits!

  • Simplify package management

It’s just intuitive and everything fits well, you don’t waste time on finding the right clothes, you are ON FIRE.

Downloading and Installing Anaconda

First, let’s get our hands on this amazing closet organizer. Head over to the Anaconda download page

Choose the Anaconda that fits your room (operating system) — they have versions for Windows, macOS, and Linux closets. Go for the Python 3.X version; it’s like choosing the latest organizer model.

Step-by-step installation guide

Windows:
1. Double-click the downloaded .exe file to launch the installer.
2. Choose “Install for me only” unless you have admin rights and want to install for all users.
3. Select an installation location or use the default.
4. In the Advanced Options, check “Add Anaconda to my PATH environment variable” for easier command-line access.
5. Click “Install” and wait for the process to complete.

macOS:
1. Double-click the downloaded .pkg file to launch the installer.
2. Follow the prompts, agreeing to the license terms.
3. Choose “Install for me only” unless you want to install for all users (requires admin rights).
4. Select an installation location or use the default.
5. On the “Destination Select” screen, ensure your main drive is selected.
6. Click “Install” and enter your password if prompted.

Linux:
1. Open a terminal window.
2. Navigate to the directory containing the downloaded file.
3. Run the following command, replacing `your-anaconda-installer.sh` with the actual filename:

bash your-anaconda-installer.sh

4. Follow the prompts, agreeing to the license terms.
5. Choose an installation location or use the default.
6. When asked if you want to initialize Anaconda3, type “yes” for easier setup.

After installation, open a new terminal or command prompt window to ensure the changes take effect by running the following command:

conda --version

Using Anaconda (the bare minimum)

Listing Environments

To see all your Anaconda environments:

conda env list

This command shows you all the environments you’ve created, with the active one marked with an asterisk (*).

Creating a New Environment

To create a new environment with a specific Python version:

conda create -n thenameofyourenv python=3.x

Replace `thenameofyourenv` with your desired environment name and `3.x` with the Python version you need (e.g., 3.8, 3.9, etc.).

Activating an Environment

To start using an environment:

conda activate thenameofyourenv

Replace `thenameofyourenv` with the name of the environment you want to activate.

Deactivating an Environment

When you’re done working in an environment:

conda deactivate

Installing Packages from a Requirements File

If you have a `requirements.txt` file with a list of packages, just make sure you activate your environment and then run:

pip install -r requirements.txt

Remember to always activate the correct environment before installing or managing packages. This ensures that you’re working within the intended isolated environment.

This article is not meant for in-depth explanation and showing you all of the features available, but just a really fast way of understanding the topic so that you can apply it instantly!

Let’s connect! Eduard Balamatiuc | LinkedIn

Made with ❤ by Sigmoid. Follow us: Facebook/Instagram/LinkedIn:

--

--

Eduard Balamatiuc
softplus-publication

Tech Director at Sigmoid. Machine Learning Engineer. Software Engineering student.