« Back to Index

Virtual Environment with venv

View original Gist on GitHub

Tags: #python

Makefile

dir := foobar
root := $(shell git rev-parse --show-toplevel)

# NOTE:
# activating the venv via `source` doesn't work so we use the . synonym instead.
venv:
	@python3 -m venv .venv/rate_control; \
	. .venv/$(dir)/bin/activate; \
	python3 -m pip install --quiet --upgrade pip; \
	python3 -m pip install --quiet -r $(root)/$(dir)/scripts/requirements.txt

purge: venv
	@. .venv/$(dir)/bin/activate; \
	python3 $(root)/$(dir)/scripts/...

example.sh

python3 --version # Python 3.11.3
ls /opt/homebrew/Cellar/python@3.11
ls /opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
ls /opt/homebrew/lib/python3.11/site-packages # above is an alias to this

python3 -m pip list

python3 -m venv testing-fastly-py-tls-bulk-cert # actually creates a subfolder you need to work within
cd testing-fastly-py-tls-bulk-cert
source bin/activate
python3 -m pip list
# from here you can create files in this directory
# or maybe you want to create them in another directory and just use the currently active venv
deactivate