I've encountered the same issue when trying to use conda environments in CI builds and Docker images. The conda documentation does provide an example when using Travis CI, but Iit does not work for me.
However, via this blog I found a working solution! Instead of activating youyour environment, you can use it by calling conda run -n my_env python my_file.py
. So, keep everything like it was until you activate your environment.
These build specs worked for me when using AWS CodeBuild:
{
"version": "0.2",
"phases": {
"pre_build": {
"commands": [
"wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh -q",
"bash miniconda.sh -b -p $HOME/miniconda",
". \"$HOME/miniconda/etc/profile.d/conda.sh\"",
"hash -r",
"conda config --set always_yes yes --set changeps1 no",
"conda update -q conda",
"conda info -a",
"conda env create -q -p ./py_env -f environment.yml"
]
},
"build": {
"commands": [
"conda run -p ./py_env python app.py"
]
}
}
}
{
"version": "0.2",
"phases": {
"pre_build": {
"commands": [
"wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh -q",
"bash miniconda.sh -b -p $HOME/miniconda",
". \"$HOME/miniconda/etc/profile.d/conda.sh\"",
"hash -r",
"conda config --set always_yes yes --set changeps1 no",
"conda update -q conda",
"conda info -a",
"conda env create -q -p ./py_env -f environment.yml"
]
},
"build": {
"commands": [
"conda run -p ./py_env python app.py"
]
}
}
}