Skip to content
Advertisement

Snakemake doesn’t activate conda environment correctly

I have a Python module modulename installed in a conda environment called myenvname.

My snakemake file consists of one simple rule:

JavaScript

The contents of the test2.py are the following:

JavaScript

When I run the above snakemake file with the command snakemake -j 1 --use-conda --conda-frontend conda I get ModuleNotFoundError, which would imply that there is no modulename in my specified environment. However, when I do the following :

JavaScript

… everything works perfectly. I have no idea what’s going on.

The full error is pasted below, with some info omitted for privacy.

JavaScript

EDIT: Typo in script fixed, the typo isn’t in the script I’m running so it’s not the issue here.

EDIT2: I’ve tried two different attempts from comments. All three attempts are run with the same CLI command snakemake -j 1 --use-conda --conda-frontend conda

Attempt 1

Rule in the snakemake:

JavaScript

In the output file I had the following (I have lots of environs and packages I’ve cut out):

JavaScript

This attempt proves that the conda environment is activated and that this environment has modulename.

Attempt 2

Same as running the script, but I’ve modified the script to include

JavaScript

So I can snag a runnable script before it’s deleted. The script has the following inserted at the start:

JavaScript

I have no idea what to do with this information.

Attempt 3

Instead of running script, I’ve ran a shell command that runs a python script.

JavaScript

It worked (showed no errors), and when I open “tata.txt” I find “1.2” which is the version of of my module.

Conclusions

The snakemake actually activates proper environment, but the problem is in script part. I have no idea why this is.

There is a similar question here, so this is a duplicate question.

Advertisement

Answer

Question is answered. Snakemake actually activates correct environment, but running a python script with the script conflicts with this directive. I don’t know if this is a bug in snakemake (version is 6.14.0) or an intentional thing. I’ve solved the problem by running the python script via shell command with python workflow/scripts/MyScript.py – it’s a bit of a problem because I had to include a CLI wrapper that would normally be solved by a snakemake object.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement