Developing software in the Real World

Quick script to (re)create my python virtualenv

When working on rst2pdf, I use pyenv as I’ve written about before. Recently, I’ve found myself needing to recreate virtualenvs for various Python versions and then recreate them to easily reset the list of packages installed into them via pip.

To my my life easier, I created a script that I can run from the command line:

This creates a new virtualenv called rst2pdf-dev-py3.9 from Python version 3.9.5, upgrade pip and install pytest, pytest-xdist & pre-commit for me. It will then switch this directory to use the new virtualenv using pyenv local. If the virtualenv already exists, it deletes it.

This is the script if anyone else finds it useful (or I lose it!):

~/bin/newenv:

Maybe it’ll be helpful to you, especially if you adapt it, as making our lives easier via simple scripts is worth it!

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *