简体   繁体   English

Makefiles无法启动conda环境

[英]Makefiles does not start conda environment

I have the makefile 我有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

but when I run it I get 但是当我运行它时,我得到了

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

although I am able to run source activate myenv outside make. 虽然我可以运行source activate myenv在外部make source activate myenv

If I alternatively try 如果我也尝试

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; \
    )

I get the error 我得到错误

/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

The error with pandas is obviously, because the source-command did not work. 熊猫的错误​​很明显,因为source-command不起作用。 And regarding that there is the message /bin/sh: 2: source: not found . 关于消息/bin/sh: 2: source: not found Maybe the issue is that I need /bin/bash instead of /bin/sh ? 也许问题是我需要/bin/bash而不是/bin/sh吗? If so, how do I get it? 如果是这样,我如何得到它?

What is the issue here? 这是什么问题?

You can use python in virtualenv directly. 您可以在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

or you can do like below: 或者您可以执行以下操作:

How to use virtualenv in makefile 如何在makefile中使用virtualenv

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" )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM