Virtualenvs 中损坏的引用 [英] Broken references in Virtualenvs

查看:13
本文介绍了Virtualenvs 中损坏的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的 Mac 上安装了一堆 dotfiles 以及一些其他应用程序(我改为 iTerm 而不是 Terminal,并将 Sublime 作为我的默认文本编辑器)但从那以后,我所有的虚拟环境都停止工作,尽管它们的文件夹.virtualenvs 内部仍然存在,每当我尝试在其中运行任何内容时,它们都会出现以下错误:

I recently installed a bunch of dotfiles on my Mac along with some other applications (I changed to iTerm instead of Terminal, and Sublime as my default text editor) but ever since, all my virtual environments have stopped working, although their folders inside .virtualenvs are still there and they give the following error whenever I try to run anything in them:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/[user]/.virtualenvs/modclass/bin/python
  Reason: image not found
Trace/BPT trap: 5

我已经删除了与 dotfiles 相关的所有文件,并将我的 .bash_profile 恢复到以前的状态,但问题仍然存在.有什么方法可以诊断问题或以简单的方式解决问题(例如,不需要重新创建所有虚拟环境)?

I have removed all the files related to dotfiles and have restored my .bash_profile to what it was before, but the problem persists. Is there any way to diagnose the problem or solve it in an easy way (e.g. not requiring to create all the virtualenvs all over again)?

推荐答案

我找到了问题的解决方案 此处,所有功劳归作者所有.

I found the solution to the problem here, so all credit goes to the author.

要点是,当您创建 virtualenv 时,会为 Homebrew 安装的 Python 创建许多符号链接.

The gist is that when you create a virtualenv, many symlinks are created to the Homebrew installed Python.

这是一个例子:

$ ls -la ~/.virtualenvs/my-virtual-env
...
lrwxr-xr-x  1 ryan staff   78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.7/Frameworks/Python.framework/Versions/2.7/Python
...

当您使用 Homebrew 升级 Python 然后运行 ​​brew cleanup 时,virtualenv 中的符号链接指向不再存在的路径(因为 Homebrew 删除了它们).

When you upgrade Python using Homebrew and then run brew cleanup, the symlinks in the virtualenv point to paths that no longer exist (because Homebrew deleted them).

符号链接需要指向新安装的 Python:

The symlinks needs to point to the newly installed Python:

lrwxr-xr-x  1 ryan staff   78 Jun 25 13:21 .Python -> /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/Python

解决方案是删除 virtualenv 中的符号链接,然后重新创建它们:

The solution is to remove the symlinks in the virtualenv and then recreate them:

find ~/.virtualenvs/my-virtual-env/ -type l -delete
virtualenv ~/.virtualenvs/my-virtual-env

在删除之前最好先检查哪些链接会被删除:

It's probably best to check what links will be deleted first before deleting them:

find ~/.virtualenvs/my-virtual-env/ -type l

在我看来,最好只删除损坏的符号链接.你可以使用 GNU find:

In my opinion, it's even better to only delete broken symlinks. You can do this using GNU find:

gfind ~/.virtualenvs/my-virtual-env/ -type l -xtype l -delete

如果你还没有,你可以用 Homebrew 安装 GNU find:

You can install GNU find with Homebrew if you don't already have it:

brew install findutils

请注意,默认情况下,随 Homebrew 安装的 GNU 程序往往以字母 g 为前缀.这是为了避免隐藏 OS X 附带的 find 二进制文件.

Notice that by default, GNU programs installed with Homebrew tend to be prefixed with the letter g. This is to avoid shadowing the find binary that ships with OS X.

这篇关于Virtualenvs 中损坏的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆