Activate Anaconda Python environment from makefile Activate Anaconda Python environment from makefile bash bash

Activate Anaconda Python environment from makefile


I had a similar problem; I wanted to create, or update, a conda environment from a Makefile to be sure my own scripts could use the python from that conda environment.
By default make uses sh to execute commands, and sh doesn't know source (also see this SO answer). I simply set the SHELL to bash and ended up with (relevant part only):

SHELL=/bin/bashCONDAROOT = /my/path/to/miniconda2..install: sometarget        source $(CONDAROOT)/bin/activate && conda env create -p conda -f environment.yml && source deactivate

Hope it helps


You should use this, it's functional for me at moment.

report.ipynb : merged.ipynb    ( bash -c "source ${HOME}/anaconda3/bin/activate py27; which -a python; \        jupyter nbconvert \        --to notebook \        --ExecutePreprocessor.kernel_name=python2 \        --ExecutePreprocessor.timeout=3000 \        --execute merged.ipynb \        --output=$< $<" )


I had the same problem. Essentially the only solution is stated by 9000. I have a setup shell script inside which I setup the conda environment (source activate python2), then I call the make command. I experimented with setting up the environment from inside Makefile and no success.

I have this line in my makefile:

installpy :   ./setuppython2.sh && python setup.py install

The error messages is:

make./setuppython2.sh && python setup.py installrunning installerror: can't create or remove files in install directoryThe following error occurred while trying to add or remove files in theinstallation directory:    [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/test-easy-install-29183.write-test'

Essentially, I was able to set up my conda environment to use my local conda that I have write access. But this is not picked up by the make process. I don't understand why the environment set up in my shell script using 'source' is not visible in the make process; the source command is supposed to change the current shell. I just want to share this so that other people don't wast time trying to do this. I know autotoools has a way of working with python. But the make program is probably limited in this respect.

My current solution is a shell script:

cat py2make.sh

#!/bin/sh# the prefix should be change to the target# of installation or pwd of the build systemPREFIX=/some/pathCONDA_HOME=$PREFIX/anaconda3PATH=$CONDA_HOME/bin:$PATHunset PYTHONPATHexport PREFIX CONDA_HOME PATHsource activate python2make

This seems to work well for me.

There were a solution for similar situation but it does not seems to work for me:

My modified Makefile segment:

installpy :   ( source activate python2; python setup.py install )

Error message after invoking make:

make( source activate python2; python setup.py install )/bin/sh: line 0: source: activate: file not foundmake: *** [installpy] Error 1

Not sure where am I wrong. If anyone has a better solution please share it.