Makefile无法启动conda环境

时间:2017-08-18 07:27:57

标签: python makefile conda

我有makefile

.PHONY: start-generate

start-generate:
    source activate myenv
    mkdir "data_channels_`date +%Y%m%d_%H%M%S`"
    python main/datageneration.py ./"data_channels_`date +%Y%m%d_%H%M%S`" 3

但是当我运行它时,我得到了

$ make start-generate
source activate myenv
make: source: Command not found
make: *** [start-generate] Error 127

虽然我可以在make之外运行source activate myenv

如果我选择尝试

start-generate:
    ( \
        source activate myenv; \
        mkdir "data_channels_`date +%Y%m%d_%H%M%S`"; \
        python main/datageneration.py ./"data_channels_`date +%Y%m%d_%H%M%S`" 3; \
    )

我收到错误

/bin/sh: 2: source: not found
Traceback (most recent call last):
  File "main/datageneration.py", line 1, in <module>
    import pandas as pd
ImportError: No module named pandas
make: *** [start-generate] Fehler 1

pandas的错误很明显,因为source-command不起作用。关于这一点,有消息/bin/sh: 2: source: not found。也许问题是我需要/bin/bash而不是/bin/sh?如果是这样,我该怎么做?

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

您可以直接在virtualenv中使用python。

.PHONY: start-generate

start-generate:
    mkdir "data_channels_`date +%Y%m%d_%H%M%S`"
    /absPATH/python main/datageneration.py ./"data_channels_`date +%Y%m%d_%H%M%S`" 3

或者你可以这样做:

How to use virtualenv in makefile

start-generate:
    ( bash -c "source activate myenv; \
        mkdir "data_channels_`date +%Y%m%d_%H%M%S`"; \
        python main/datageneration.py ./"data_channels_`date +%Y%m%d_%H%M%S`" 3" )