Creating and Managing Environments
Duration: 5 min
This module delves into the essential practice of creating and managing environments using Conda, a powerful package and environment management system. Understanding how to effectively create and manage environments is crucial for maintaining project-specific dependencies and ensuring reproducibility in your work.
Creating a New Environment
Creating a new environment in Conda allows you to isolate your project's dependencies from the global Python installation. This ensures that different projects can have their own set of libraries without conflicts. To create a new environment, you use the conda create command followed by the environment name and the packages you want to include.
import conda
# Create a new environment named'myenv' with Python 3.8
conda.create(name='myenv', python='3.8')Solving environment...
# Packages that will be installed
The following NEW packages will be installed:
package build
Proceed ([y]/n)? y
# Installation process
# Environment created successfully
Activating and Deactivating Environments
Once an environment is created, you can activate it using the conda activate command. This will switch your shell session to the specified environment, allowing you to install and use packages within that environment. To deactivate the environment and return to the base environment, use the conda deactivate command.
import conda
# Activate the 'myenv' environment
conda.activate('myenv')
# Install a package within the activated environment
conda.install('numpy')
# Deactivate the current environment
conda.deactivate()💡 Tip: Always remember to deactivate your environment when you are done working in it to avoid accidentally installing packages in the wrong environment.
❓ What command is used to create a new environment in Conda?
❓ How do you deactivate an active environment in Conda?