GitHub Action - Workflow - Python Package Using Conda

I created this workflow with a conda environment.yaml. All 3rd party libs in this file are installed.
But unittests using these 3rd party libs failed with error: No module named ‘socks’

Looking through the log, it seems that the conda env is not activated. I tried to activate the env but got conda init error.

Ideally, the conda env should be activated right after installation.

@psilons,

If possible, please share your repository with us so that we can check more detailed configurations of your workflow to analyze the root cause.
If your repository is private, you can share an example to reproduce the issue in a public repository.

In addition, did you try installing these 3rd party libs with the same steps (related command lines) on your local machines? Did the same issue occur?

@brightran,

Thanks for the reply.

The repo is: https://github.com/psilons/pypigeonhole-simple-utils

It works on my local many times.

I also run conda list before the unit tests. The output shows all needed libs are there. It’s in the log.

Thanks for the help!

@psilons,

I have created an issue ticket (actions/virtual-environments#1732) to help you report the problem to the appropriate engineering team for further investigation and evaluation.
You can follow this issue ticket and add your comments to it.

In addition, you mentioned,

It works on my local many times.

You also can try installing a self-hosted runner on your local machine to run the workflow to see if the problem still exists.

I just had a quick look at your workflow action, and you are not activating/using the conda environment. In other words — as it seems you have discovered — the python executable being used in your workflow is the system python, not the one managed by your conda environment.

The easiest way to resolve this is to activate the conda environment. Either append the following to an existing step (for example “Install dependencies”) or add a new step;

conda activate base

Note that base here refers to the environment you used in your “Install dependencies” step.

Another alternative is to use the new conda run command. To do that, add conda run in from of all of your python commands (for example in the “Unit Tests” step). By using conda run you can run any executable as if the conda environment has been activated, but without actually having to explicitly activate it. I personally prefer the latter, but it seems like the best option for you is to use conda activate <NAME>.

Hi,
Thanks for the reply.
I tried conda activate base, but it failed with sam conda init error. Seems that the error is related to permission.

However, conda run does work. Very nice.

Really appreciate your help.

1 Like