简体   繁体   English

Mac OSX Catalina 破解了所有 Python Venv

[英]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.最近刚刚升级到 Mac OSX Catalina,它似乎破坏了我所有的 Python venv。

  1. I have a venv that I previously created before upgrading to Catalina.我有一个我之前在升级到 Catalina 之前创建的 venv。
  2. I can activate the venv without issue: source venv/bin/activate我可以毫无问题地激活 venv: 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.当我输入pythonpython3 ,它实际上运行系统 Python 解释器,而不是我的 venv 中预期的 Python 解释器。

With my venv activated...随着我的 venv 激活...

>>> 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 .我希望它指向/Users/<username>/<path-to-venv>/venv/bin/python3

  1. If I try to run that Python interpreter directly:如果我尝试直接运行该 Python 解释器:
>>> /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.如果我在 Finder 中导航到这个 venv 目录,我可以看到python3文件存在,尽管它实际上是一个别名。 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.如果我双击它,会弹出一条错误消息,内容为: 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.所以我认为这些 venv 的工作方式是它们基于对现有 Python 解释器安装的引用。 Evidently running a venv invokes these references, and if the original installation is broken it fails.显然运行 venv 会调用这些引用,如果原始安装被破坏,它就会失败。 I know that Catalina jacked with the default Python settings and went so far as to change installation directories.我知道 Catalina 使用默认的 Python 设置,甚至更改了安装目录。

Has anyone else encountered this?有人遇到过这种情况么? Can anyone offer tips to fix this?任何人都可以提供解决此问题的提示吗? This seems to affect all my venv virtual environments across my system.这似乎影响了我系统中的所有 venv 虚拟环境。

You can try to create a new venv in the same folder or to update your existing venv.您可以尝试在同一文件夹中创建一个新的 venv 或更新您现有的 venv。 With all the following I assume you've created your virtual environments with the bundled venv module通过以下所有内容,我假设您已经使用捆绑的venv模块创建了虚拟环境

  • 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.为了更新, --upgrade参数就是你要找的。

You need to run it with the targeted Python version, for example in this case:您需要使用目标 Python 版本运行它,例如在这种情况下:

python3 -m venv --upgrade <path_to_dir>

for more details, see my answer here有关更多详细信息,请在此处查看我的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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