从makefile激活Anaconda Python环境
我想使用makefile来构建我的项目环境,使用makefile和,因此我应该能够克隆repo并简单地运行从makefile激活Anaconda Python环境,python,bash,makefile,virtualenv,anaconda,Python,Bash,Makefile,Virtualenv,Anaconda,我想使用makefile来构建我的项目环境,使用makefile和,因此我应该能够克隆repo并简单地运行makemyproject myproject: build build: @printf "\nBuilding Python Environment\n" @conda env create --quiet --force --file environment.yml @source /home/vagrant/miniconda/bin/activate myprojec
makemyproject
myproject: build
build:
@printf "\nBuilding Python Environment\n"
@conda env create --quiet --force --file environment.yml
@source /home/vagrant/miniconda/bin/activate myproject
但是,如果我尝试这样做,我会得到以下错误
make:source:未找到命令
make:**[来源]错误127
我已经搜索了一个解决方案,但是[this question/answer()表明我不能在makefile中使用source
然而,他提出了一个解决方案(并获得了几票赞成票),但这对我也不起作用
(\source/home/vagrant/miniconda/bin/activate myproject\ ) /bin/sh:2:来源:未找到 make:**[来源]错误127 我还尝试将
source activate
步骤移动到一个单独的bash脚本中,并从makefile执行该脚本。这不起作用,我假设是出于类似的原因,即我正在shell中运行source
我应该补充一点,如果我从终端运行
source activate myproject
,它会正常工作。我也有同样的问题。基本上唯一的解决方案是9000。我有一个安装shell脚本,在其中我设置了conda环境(source activate python2),然后调用make命令。我尝试从Makefile内部设置环境,但没有成功
我的makefile中有一行:
installpy :
./setuppython2.sh && python setup.py install
错误消息为:
make
./setuppython2.sh && python setup.py install
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/test-easy-install-29183.write-test'
基本上,我可以设置我的conda环境以使用我具有写访问权限的本地conda。但这不是make进程所选择的。我不明白为什么在我的shell脚本中使用“source”设置的环境在make进程中不可见;source命令应该更改当前shell。我只想我知道Autotools有一种使用python的方法,但是make程序在这方面可能是有限的
我当前的解决方案是一个shell脚本:
cat py2make.sh
这似乎对我很有效
类似的情况也有类似的解决方案,但似乎对我不起作用:
我修改的Makefile段:
installpy :
( source activate python2; python setup.py install )
调用make后出现错误消息:
make
( source activate python2; python setup.py install )
/bin/sh: line 0: source: activate: file not found
make: *** [installpy] Error 1
不确定我错在哪里。如果有人有更好的解决方案,请与我们分享。我有一个类似的问题;我想从Makefile创建或更新conda环境,以确保我自己的脚本可以使用该conda环境中的python。
默认情况下,make使用sh执行命令,而sh不知道源代码(另请参见)。我只是将SHELL设置为bash,结果是(仅相关部分):
希望它能帮上忙,你应该用这个,它现在对我来说很实用
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=$< $<" )
report.ipynb:merged.ipynb
(bash-c“source${HOME}/anaconda3/bin/activate py27;它是python\
朱皮特·恩康维特\
--记\
--executeProcessor.kernel_name=python2\
--ExecuteProcessor.timeout=3000\
--执行merged.ipynb\
--output=$<$读取/home/vagrant/miniconda/bin/activate
的内容。请注意,source
是一个内置的shell,不是可调用的可执行文件,它在当前shell的上下文中执行文件的语句。由于make
运行不同的shell副本,因此您无法在当前shell中从中激活virtualenvshell,就像你不能从makefile中更改当前shell的目录一样。因此,基本上我无法用makefile实现这一点?你可以克隆一个repo,激活shell中的一个环境,并在调用shell时运行一个makefile步骤(可能是另一个makefile)。例如,/bin/sh-c“源路径/到/激活;使我成为三明治"
@PhilipO'Brien看看你最后选择了什么方法真的很有趣。我也面临着同样的限制。非常感谢你的提示-将我的shell设置为Bash shell是让源代码命令工作的诀窍!似乎还需要使用&
才能让命令在我的环境中运行这真的很有帮助
SHELL=/bin/bash
CONDAROOT = /my/path/to/miniconda2
.
.
install: sometarget
source $(CONDAROOT)/bin/activate && conda env create -p conda -f environment.yml && source deactivate
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=$< $<" )