6

Just recently upgraded to Mac OSX Catalina, and it seems to have broken all my Python venv's.

  1. I have a venv that I previously created before upgrading to Catalina.
  2. I can activate the venv without issue: source venv/bin/activate
  3. When I type python or python3, it actually runs the system Python interpreters, instead of the expected Python interpreter in my venv.

With my venv activated...

>>> which python
/usr/bin/python
>>> which python3
/usr/local/bin/python3

I expect that to point to /Users/<username>/<path-to-venv>/venv/bin/python3.

  1. If I try to run that Python interpreter directly:
>>> /Users/<username>/<path-to-venv>/venv/bin/python3

bash: /Users/<username>/<path-to-venv>/venv/bin/python3: No such file or directory
  1. If I navigate to this venv directory in Finder, I can see that the python3 file exists, although it's actually an alias. If I double-click on it, I get an error message that pops up that reads: The operation can't be completed because the original item for "Python3" can't be found.

So I think the way these venv's work is that they are based on references to existing Python interpreter installations. Evidently running a venv invokes these references, and if the original installation is broken it fails. I know that Catalina jacked with the default Python settings and went so far as to change installation directories.

Has anyone else encountered this? Can anyone offer tips to fix this? This seems to affect all my venv virtual environments across my system.

hobscrk777
  • 2,347
  • 4
  • 23
  • 29
  • 3
    It would probably be easier to regenerate the virtual environments than to fix one that depended on pre-update paths. – chepner Dec 21 '19 at 19:07
  • 1
    Activating a virtual environment is a very lightweight operation: it just sets some environment variables like `PATH`. It doesn't depend on the interpreters you expect to find actually existing. – chepner Dec 21 '19 at 19:10
  • @hobscrk777 OP did you find the solution? I am having the same problem – Craig Nathan Oct 01 '21 at 09:38

1 Answers1

1

You can try to create a new venv in the same folder or to update your existing venv. With all the following I assume you've created your virtual environments with the bundled venv module

  • For the creation it's the command you've probably already used
python3 -m venv <path_to_dir>
  • In order to update, the --upgrade parameter is what you're looking for.

You need to run it with the targeted Python version, for example in this case:

python3 -m venv --upgrade <path_to_dir>

for more details, see my answer here

RMPR
  • 3,368
  • 4
  • 19
  • 31