Issue
I have Python 3.12 and virtualenv 20.25.0, both installed via Homebrew. The last time I used my computer, virtualenv was functioning properly. The very next time I try to use virtualenv
, I am greeted with this error:
> $ virtualenv --version
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 5, in <module>
from virtualenv.__main__ import run_with_catch
File "/usr/local/lib/python3.12/site-packages/virtualenv/__init__.py", line 3, in <module>
from .run import cli_run, session_via_cli
File "/usr/local/lib/python3.12/site-packages/virtualenv/run/__init__.py", line 7, in <module>
from virtualenv.app_data import make_app_data
File "/usr/local/lib/python3.12/site-packages/virtualenv/app_data/__init__.py", line 11, in <module>
from .read_only import ReadOnlyAppData
File "/usr/local/lib/python3.12/site-packages/virtualenv/app_data/read_only.py", line 5, in <module>
from virtualenv.util.lock import NoOpFileLock
File "/usr/local/lib/python3.12/site-packages/virtualenv/util/lock.py", line 12, in <module>
from filelock import FileLock, Timeout
ModuleNotFoundError: No module named 'filelock'
The internet happens to not be very helpful and I have done nothing myself in the time between using virtualenv successfully and now. What could've happened here?
Solution
pip install virtualenv
installs filelock
as a dependency. If Homebrew didn't install filelock
it's a bug in its formulas.
Try to fix by installing filelock
directly:
sudo python3.12 -m pip install --break-system-packages filelock
If that doesn't help try to upgrade the entire stack of dependencies for virtualenv
:
sudo python3.12 -m pip install --break-system-packages --upgrade virtualenv
PS. I often recommend to avoid sudo
but this time it's required to fix/upgrade what is installed under /usr/local
Answered By - phd Answer Checked By - Katrina (WPSolving Volunteer)