I'll just add what I've been using to make this work seamlessly in various projects.
It uses GNU Make, by providing a venv
target one can use as a dependency to other targets to ensure a properly created virtual environment.
The venv
target itself depends on a, albeit configurable, requirements.txt
; the standard python requirements file.
A target test
is include as an example of how one would use this.
The trick is to create a symlink to the installed system package. ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi
, where $DIST_PACKAGE
is the location of the python installed libraries on your system.
For those not familiar with make. Create a file named Makefile
in the root of your project, copy the contents bellow, and issue the command make configure && make venv
.
Makefile
# directory to store virtual environment
VENV_NAME=venv
# python runtime version
PYTHON_VER=3.6
# python executble
PYTHON=${VENV_NAME}/bin/python${PYTHON_VER}
# python local libraries location
DIST_PACKAGES=/usr/lib/python3/dist-packages
# pip requirements file
REQUIREMENTS=requirements.txt
configure: ## Install required debian packages.
sudo apt-get -y install python${PYTHON_VER} python3-pip libgirepository1.0-dev
python3 -m pip install virtualenv pygobject
make venv
venv: ## Recreates the virtual environment if needed.
venv: $(VENV_NAME)/bin/activate
$(VENV_NAME)/bin/activate: ${REQUIREMENTS}
test -d $(VENV_NAME) || virtualenv -p python${PYTHON_VER} $(VENV_NAME)
${PYTHON} -m pip install -U pip
${PYTHON} -m pip install -r ${REQUIREMENTS}
ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi
touch $@
test: ## Runs the test suite.
test: venv
$(PYTHON) -m pytest tests