How to use RMarkdown for Python with Virtual Environments

I’m currently evaluating different publishing workflows for my academic writing. One option that seems to be increasingly popular is the use of RMarkdown as a source document, from which you then compile into HTML, LaTeX or whatever else you need. For the code used in the document, RMarkdown not only supports the execution of R, but a whole bunch of languages, including Python, thanks to the knitr package. One problem I had when I first came across RMarkdown a couple of years ago is that it didn’t really support using virtual environments when using Python.