Why is conda environment created with VSCode not reachable in a bash script but conda environment created with conda create is?

38 Views Asked by At

I'm working with WSL, VS Code and Miniconda. I'm creating a bash script to activate a conda environment and run a Python script. This conda environment was created with VS Code inside a project folder (something like /mnt/c/Users/windows_username/projects/project1/.conda) and not in the miniconda environments folder (something like /home/linux_username/miniconda3/envs/environment1). The bash script would be the following:

#!/bin/bash
source /home/linux_username/miniconda3/bin/activate /mnt/c/Users/windows_username/projects/project1/.conda
python /mnt/c/Users/windows_username/projects/project1/python_script.py

I run it with bash bash_script.sh and get the following error:

EnvironmentLocationNotFound: Not a conda environment: /mnt/c/Users/windows_username/projects/project1/.conda

After looking for a solution and making no progress, I created another project and a conda environment using conda directly instead of VS Code to check whether I would get the same error:

conda create --name project2_env python=3.10

I modify the bash script accordingly (see below) and run it:

#!/bin/bash
source /home/linux_username/miniconda3/bin/activate project2_env
python /mnt/c/Users/windows_username/projects/project2/python_script.py

In this case, everything works well, which seems to suggest there's an issue with the name or path of the conda environment created with VS Code.

I'd appreciate any help with this issue. Thanks!

0

There are 0 best solutions below