Skip to content

Instantly share code, notes, and snippets.

@fawkesley
Last active April 11, 2020 17:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fawkesley/869df266ef36231014f434686202eb9f to your computer and use it in GitHub Desktop.
Save fawkesley/869df266ef36231014f434686202eb9f to your computer and use it in GitHub Desktop.
Makefile for activating a virtualenv and installing requirements. Uses requirements-to-freeze.txt / requirements.txt pattern
# Put *unversioned* requirements in `requirements-to-freeze.txt` as described below.
# `requirements.txt` will be automatically generated from `pip freeze`
# https://www.kennethreitz.org/essays/a-better-pip-workflow
venv/bin/activate: requirements-to-freeze.txt
rm -rf venv/
test -f venv/bin/activate || virtualenv -p $(shell which python3) venv
. venv/bin/activate ;\
pip install -Ur requirements-to-freeze.txt ;\
pip freeze | sort > requirements.txt
touch venv/bin/activate # update so it's as new as requirements-to-freeze.txt
.PHONY: run
run: venv/bin/activate
. venv/bin/activate ; \
python3 mycode.py
@lewis6991
Copy link

Why test for venv/bin/activate when you have already deleted venv?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment