简体   繁体   中英

Mac OSX Catalina Broke All Python Venv's

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM