Search code examples
pythonmakefilevirtualenv

How to use virtualenv in makefile


I want to perform several operations while working on a specified virtualenv.

For example command

make install

would be equivalent to

source path/to/virtualenv/bin/activate
pip install -r requirements.txt

Is it possible?


Solution

  • In make you can run a shell as command. In this shell you can do everything you can do in a shell you started from comandline. Example:

    install:
        ( \
           source path/to/virtualenv/bin/activate; \
           pip install -r requirements.txt; \
        )
    

    Attention must be paid to the ;and the \.

    Everything between the open and close brace will be done in a single instance of a shell.