I recently ran into some issues using Python venvs by accidently recreating a venv in the same location as an existing one.
Steps to reproduce:
- Created a venv using Python 3.10.11
- Installed numpy 2.1.2 via pip
- Recreated the venv in the same location using Python 3.12.7
- Attempted to reinstall numpy 2.1.2 via pip, but pip said it is already installed
- Ran
import numpy as np
in the venv
Resulting error (from numpy):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
It seems like the recreation of the venv messes up something with the numpy installation. As I said above, this was an accident in the first place – I should have created the second venv in a new location. However, I’m curious what might be happening here, and more generally what the consequences of overwriting existing venvs with new ones might be?
You need to sign in to view this answers
Leave feedback about this