My workflow:
One time setup
$ python -m venv ve
$ source ve/bin/activate
$ pip install pygments WeasyPrint
Then $ pygmentize -f html src.py | weasyprint - out.pdf
Both pygmentize and weasyprint have many options to play with. I find a set and create a shell script.This also does pngs, etc:
$ pygmentize -f html src.py | weasyprint - out.png