Mac OSX Catalina Broke All Python Venv's

hob*_*777 6 python macos virtualenv python-3.x macos-catalina

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)
  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.

RMP*_*MPR 1

您可以尝试在同一文件夹中创建新的 venv 或更新现有的 venv。通过以下所有内容,我假设您已经使用捆绑的venv模块创建了虚拟环境

  • 对于创建,它是您可能已经使用过的命令
python3 -m venv <path_to_dir>
Run Code Online (Sandbox Code Playgroud)
  • 为了更新,--upgrade参数就是您要查找的内容。

您需要使用目标 Python 版本运行它,例如在本例中:

python3 -m venv --upgrade <path_to_dir>
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅我的回答这里