CARVIEW |
Select Language
HTTP/2 200
date: Fri, 10 Oct 2025 11:20:12 GMT
server: Fly/6f91d33b9d (2025-10-08)
content-type: text/html; charset=utf-8
content-encoding: gzip
via: 2 fly.io, 2 fly.io
fly-request-id: 01K76XK4JDJA7E982K9CAP89NP-bom
Quickly testing code in a different Python version using pyenv | Simon Willison’s TILs
Quickly testing code in a different Python version using pyenv
I had a bug that was only showing up in CI against Python 3.8.
I used the following pattern with pyenv to quickly run the tests against that specific version.
(I had previously installed pyenv
using brew install pyenv
.)
Seeing what versions I had already
pyenv versions
This outputs (on my machine):
system
3.7.16
3.8.17
To see all possible versions:
pyenv install --list
That's a long list! I grepped it for 3.8:
pyenv install --list | grep '3.8'
3.8.0
3.8-dev
3.8.1
3.8.2
...
3.8.14
3.8.15
3.8.16
3.8.17
...
Installing a specific version
I installed 3.8.17 like this:
pyenv install 3.8.17
This took a long time, because it compiled it from scratch.
Using that version via a virtual environment
I decided to use that version of Python directly. The binary was installed here:
~/.pyenv/versions/3.8.17/bin/python
I created a temporary virtual environment in /tmp
like this:
~/.pyenv/versions/3.8.17/bin/python -m venv /tmp/py38env
Then installed my current project into that environment like so:
/tmp/py38env/bin/pip install -e '.[test]'
Now I can run the tests like this:
/tmp/py38env/bin/pytest
Related
- docker Run pytest against a specific Python version using Docker - 2022-09-05
- github-actions Testing against Python 3.11 preview using GitHub Actions - 2022-02-02
- python Running PyPy on macOS using Homebrew - 2022-09-14
- sqlite Building a specific version of SQLite with pysqlite on macOS/Linux - 2021-08-14
- python macOS Catalina sort-of includes Python 3 - 2020-04-21
- sqlite Using LD_PRELOAD to run any version of SQLite with Python - 2020-06-17
- macos Installing Python on macOS with the official Python installer - 2022-02-28
- github-actions actions/setup-python caching for setup.py projects - 2022-11-28
- python How to call pip programatically from Python - 2020-08-11
- python Installing lxml for Python on an M1/M2 Mac - 2023-01-27
Created 2023-07-10T14:21:04-07:00 · Edit