💻Exploring New Conda Environment Creation Commands 💻

Mangesh kendre
2 min readJan 15, 2024

--

Conda, a powerful package and environment management system, provides various commands for creating and managing environments. In this article, we’ll explore some of the new and useful conda environment creation commands to streamline your development workflow.

1. Creating a Basic Environment

Creating a basic environment involves specifying the Python version and environment name. The following command creates an environment named myenv with Python version 3.9:

# cheack python version
python --version

# cheack available env
conda info --env

#create new env
conda create --name myenv python=3.9

#go to particular and activate env
activate myenv

#deactivate env
deactivate myenv

This command initializes a new environment and installs Python 3.9 in it. You can customize the Python version by adjusting the python parameter.

2. Specifying Channels and Packages

Conda allows you to specify channels from which packages are fetched during environment creation. The --override-channels option lets you override the default channels with your own:

# if we face above error in cmd , then use below command.
conda create --name myenv python=3.9 --override-channels -c conda-forge

In this example, the conda-forge channel is used instead of the default channels. This can be beneficial for accessing a broader range of packages.

3. Creating an Environment from a YAML File

Conda environments can be defined in YAML files, making it easy to share and recreate environments. Create a environment.yml file with the following content:

name: myenv
channels:
- conda-forge
dependencies:
- python=3.9
- numpy
- pandas
- matplotlib

You can then create the environment using:

conda env create --file environment.yml

4. Cloning an Environment

Cloning an existing environment allows you to reproduce it with all its dependencies intact. To clone an environment named source_env to a new one called target_env, use:

conda create --name target_env --clone source_env

This command duplicates the specified environment, preserving all installed packages and configurations.

5. Creating an Environment with a Specific Package Version

Specify package versions during environment creation to ensure compatibility. For example, to create an environment with NumPy version 1.20.3, use:

conda create --name myenv python=3.9 numpy=1.20.3

This ensures that the specified version of NumPy is installed in the new environment.

6. Creating an Environment with GPU Support

For environments requiring GPU support, you can use conda to install packages compatible with CUDA. To create a GPU-enabled environment, use:

conda create --name myenv python=3.9 cudatoolkit=10.1 tensorflow-gpu

This example creates an environment with TensorFlow GPU support and specifies the CUDA toolkit version.

Conclusion

Conda provides a versatile set of commands for creating and managing environments. Whether you’re specifying channels, creating from YAML files, or cloning existing environments, these commands empower you to tailor environments to your specific needs. Experiment with these new conda environment creation commands to enhance your development workflows and ensure reproducibility in your projects.

--

--

No responses yet