删除Ruby后如何修复macOS Vim电源线错误

2024-06-09 09:41:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下方法删除了Mac上的Ruby:

brew remove -f ruby
brew cleanup

Homebrew显示了一条消息,“Vim有Ruby依赖项,我是否仍要删除Ruby(y/N)”,我选择了“y”,Ruby被删除

然后,我再次安装了Ruby,其中包括:

brew install ruby

之后,Vim开始在启动时给我错误信息:

vim .
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:17:in `require': incompatible library version - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/stringio.bundle (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:17:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:1230:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:1230:in `<module:Gem>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:116:in `<top (required)>'
    from <internal:gem_prelude>:4:in `require'
    from <internal:gem_prelude>:4:in `<internal:gem_prelude>'
Traceback (most recent call last):
  File "<string>", line 9, in <module>
  File "/Users/ruslan/.vim/bundle/powerline/powerline/__init__.py", line 11, in <module>
    from powerline.lib.config import ConfigLoader
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/config.py", line 11, in <module>
    from powerline.lib.threaded import MultiRunnedThread
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/threaded.py", line 7, in <module>
    from powerline.lib.monotonic import monotonic
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/monotonic.py", line 19, in <module>
    import ctypes
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 555, in <module>
    _reset_cache()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 279, in _reset_cache
    CFUNCTYPE(c_int)(lambda: None)
MemoryError
An error occurred while importing powerline module.
This could be caused by invalid sys.path setting,
or by an incompatible Python version (powerline requires
Python 2.6, 2.7 or 3.2 and later to work). Please consult
the troubleshooting section in the documentation for
possible solutions.
Error detected while processing /Users/ruslan/.vim/bundle/powerline/powerline/bindings/vim/plugin/powerline.vim:
line  157:
Traceback (most recent call last):
  File "<string>", line 53, in <module>
  File "<string>", line 9, in powerline_troubleshoot
  File "/Users/ruslan/.vim/bundle/powerline/powerline/__init__.py", line 11, in <module>
    from powerline.lib.config import ConfigLoader
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/config.py", line 11, in <module>
    from powerline.lib.threaded import MultiRunnedThread
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/threaded.py", line 7, in <module>
    from powerline.lib.monotonic import monotonic
  File "/Users/ruslan/.vim/bundle/powerline/powerline/lib/monotonic.py", line 19, in <module>
    import ctypes
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 555, in <module>
    _reset_cache()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 279, in _reset_cache
    CFUNCTYPE(c_int)(lambda: None)
MemoryError
Press ENTER or type command to continue

之后,我将以下行添加到我的~/.vimrc中:

let $RUBYHOME=$HOME."~/.rbenv/versions/2.7.0"
set rubydll=$HOME/.rbenv/versions/2.7.0/lib/libruby.2.7.dylib
let g:powerline_pycmd = 'py3'

Vim启动时的错误消息已更改为:

Error detected while processing /Users/ruslan/.vim/bundle/vim-rubyhash/plugin/rubyhash.vim:
line   54:
E370: Could not load library /Users/ruslan/.rbenv/versions/2.7.0/lib/libruby.2.7.dylib
E266: Sorry, this command is disabled, the Ruby library could not be loaded.
You need vim compiled with Python 2.6, 2.7 or 3.2 and later support
for Powerline to work. Please consult the documentation for more
details.
E370: Could not load library /Users/ruslan/.rbenv/versions/2.7.0/lib/libruby.2.7.dylib
E266: Sorry, this command is disabled, the Ruby library could not be loaded.
Press ENTER or type command to continue

我还尝试:

brew uninstall vim ruby
brew cleanup
rbenv global system
brew install vim ruby   

但这没用

我的系统:

macOS => Mojave

vim --version => 
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 19 2019 19:08:44)
Included patches: 1-503, 505-680, 682-1283, 1365

which vim => /usr/bin/vim
which ruby => /Users/myname/.rbenv/shims/ruby
ruby -v => ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
python3 --version => Python 3.7.7

我找不到任何有助于解决这个问题的来源


Tags: infrompyliblinevimsystemusers
1条回答
网友
1楼 · 发布于 2024-06-09 09:41:35

macOS预装了Vim的命令行版本:

l /usr/bin/vim
-rwxr-xr-x  1 root  wheel   2.0M Jan 23 06:58 /usr/bin/vim

它的设置是为了与预先安装的Ruby版本配合使用,以实现其自身的目的:

l /usr/bin/ruby
-r-xr-xr-x  1 root  wheel    36K Jan 23 06:59 /usr/bin/ruby

因此,没有必要安装不同版本的Ruby或Vim,因为它们可以一起工作

如果您想要其中一个的最新版本,Homebrew可以安装它们,正如您所发现的,但是从那时起,您应该将它们作为一对来使用。删除自制安装的Ruby现在会让你的Vim感到困惑,因为它看到的Ruby是Apple安装的,可能比它想要的版本旧:

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:17:in `require': incompatible library version - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/stringio.bundle (LoadError)

因此,您可以使用其中一个:

  • 卸载自制Vim,然后使用安装的Vim和Ruby Apple
  • 卸载您的自制Vim,然后使用自制重新安装Ruby和Vim,忽略苹果安装的版本
  • 首先做,然后安装MacVim,这是我使用的,它可以与苹果的Ruby一起工作,或者在rbenvRVM的控制下工作。这是我的建议

由于Vim能够从任何地方加载脚本,因此您可以轻松地在主目录中创建.vimrc.gvimrc,并将Vim指向保存到目录中的插件。我有~/.vim包含许多插件,所有插件都可以与苹果的Vim、MacVim的CLIvim及其GUI版本的GVim和NVim一起使用。(我的.vimrc.gvimrc实际上是到~/.vim/vimrc~/.vim/gvimrc的软链接,只是为了把所有东西都放在一个整洁的堆中。)我使用rbenv,可以根据需要更新Rubies,然后它就会自动消失。有时我会在更新后为“Seeing Is Believing”调整一些内容,但这是一个简单的修复方法

相关问题 更多 >