Skip to content
Latchkey

nox "--reuse-existing-virtualenvs" Runs With Stale Dependencies in CI

nox can reuse a session’s virtualenv to save time (-r/-R). -R also skips the install step entirely. When dependencies changed, a reused env runs against old packages and the session fails.

What this error means

A nox session fails with a missing or outdated package after deps changed, but passes once you drop -R/-r so the env is recreated and reinstalled. The session code is fine - the reused venv was stale.

nox output
nox > Re-using existing virtualenv at .nox/tests.
nox > Skipping install step for reused virtualenv.
ImportError: cannot import name 'NewThing' from 'mylib'   # old mylib still installed

Common causes

-R skips the install step

nox -R reuses the venv and skips session.install, so any dependency change is not applied to the reused environment.

Reused venv predates the dependency change

-r reuses the existing .nox/<session> venv; if it was created before the deps changed and install conditions did not trigger, it stays stale.

How to fix it

Run sessions clean when deps change

Drop the reuse flags so nox recreates the venv and reinstalls.

Terminal
nox            # fresh venv + install (no -r/-R)
nox -s tests   # clean run of one session

Reuse the venv but not the install

Reuse the environment for speed while still reinstalling dependencies.

Terminal
nox -r -s tests   # reuse venv, but DO run install (unlike -R)

How to prevent it

  • Use -r, not -R, when dependencies may have changed.
  • Recreate nox venvs in CI when the lock/deps change.
  • Key any .nox cache on dependency files so it busts on change.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →