CondaValueError: the target prefix is the base prefix. aborting. error occurs when you “attempt to install a conda package into the base environment, which is not allowed.” The base environment is a protected environment where the packages cannot be installed or removed.
To fix this error, create a new conda environment, and install the package in the new environment.
Let’s follow the steps one by one.
Solution 1: Creating a new conda environment
Step 1: Create a new environment.
conda create --name newenv
Here you can replace newenv with the environment name.
Step 2: Ask for confirmation
When conda asks you to proceed, type y
proceed ([y]/n)?
This creates the newenv environment in /envs/. No packages will be installed in this environment.
Step 3: Create an environment with a specific version of Python
conda create -n newenv python=3.9
You can also create an environment with a particular package. For example, let’s install numpy.
conda create -n newenv scipy
And that’s it. Now, you have a fully functional conda environment.
Step 4: Activate the environment
conda activate newenv
Solution 2: Using an environment.yml file
A conda environment.yml file specifies the packages and dependencies required for a conda environment.
The environment.yml file follows the YAML syntax and contains the name of the environment and the packages required to be installed in the environment.
Let’s create an environment.yml file and add the below code inside it.
name: newenv
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- numpy
- pandas
You can create an environment from an environment.yml file using the below code.
conda env create -f environment.yml
The above command will resolve the CondaError by creating an environment named newenv with the installed packages and dependencies.
You can activate a conda environment using this command: conda activate.
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.