I am working with a conda environment that contains multiple packages, and I am trying to debug a Python script that calls those packages via shell commands. While selecting interpreter via VS Code uses that environment’s packages, it does not allow me to use the packages installed directly via conda.
Take this code example:
import os
import sys
print(f'python: {sys.executable}')
print(f"env: {os.environ['CONDA_DEFAULT_ENV']}")
print('Trying trimmomatic:')
print(os.system('trimmomatic'))
print('nTrying trimmomatic ater explicit conda activate:')
print(os.system('source ~/.bashrc; conda activate myenv; trimmomatic'))
I have an environment myenv
that has the tool trimmomatic
installed. You can see from the sys.executable
(and from the bottom right corner of VS Code) that the interpreter is selected. However, in the second line, you can see that the conda environment is not activated, and instead base
is the active environment. As a result, I cannot use the tool unless I activate the environment in conda explicitly. So this is the output I get:
python: /path/to/envs/myenv/bin/python
env: base
Trying trimmomatic:
sh: line 1: trimmomatic: command not found
32512
Trying trimmomatic after explicit conda activate:
Usage:
PE [-version] [-threads <threads>] [-phred33|-phred64] [-trimlog <trimLogFile>] [-summary <statsSummaryFile>] [-quiet] [-validatePairs] [-basein <inputBase> | <inputFile1> <inputFile2>] [-baseout <outputBase> | <outputFile1P> <outputFile1U> <outputFile2P> <outputFile2U>] <trimmer1>...
or:
SE [-version] [-threads <threads>] [-phred33|-phred64] [-trimlog <trimLogFile>] [-summary <statsSummaryFile>] [-quiet] <inputFile> <outputFile> <trimmer1>...
or:
-version
256
How can I get VS Code to really activate the environment?