Virtualenvs中的参考损坏 [英] Broken references in Virtualenvs

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

问题描述

我最近在Mac上安装了一堆点文件以及其他一些应用程序(我改为使用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

我已经删除了所有与dotfile相关的文件,并将.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天全站免登陆