0

I have the 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.

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. And regarding that there is the message /bin/sh: 2: source: not found. Maybe the issue is that I need /bin/bash instead of /bin/sh? If so, how do I get it?

What is the issue here?

Make42
  • 12,236
  • 24
  • 79
  • 155

1 Answers1

1

You can use python in virtualenv directly.

.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

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" )
Make42
  • 12,236
  • 24
  • 79
  • 155
caimaoy
  • 1,148
  • 1
  • 11
  • 25
  • That does not work: Everyone has their conda environment somewhere else. When I give the Makefile to a colleague, it won't work anymore if I do it like you suggest. – Make42 Aug 18 '17 at 08:03
  • Consider different environment, `source activate myenv` the name of virtualenv may be differnet. You can write the Makefile like a unit-test, `init` to create a virtualenv with the name you like `pip install requirements`, then `start-generate` – caimaoy Aug 18 '17 at 08:43
  • 1
    In my company we have conventions how "myenv" is supposed to be called, so that is not an issue. I do not want to have a new environment created every time I run start-generate. I am not sure what you mean exactly. Can you post the Makefile you are thinking of? – Make42 Aug 18 '17 at 10:35
  • I found a way to do it. – caimaoy Aug 21 '17 at 03:18
  • We got closer, but it does not work yet. I updated my question accordingly. – Make42 Aug 21 '17 at 09:14
  • I did it. I added the required code into your answer. Please except the edit. – Make42 Aug 21 '17 at 09:32