捆绑器版本不匹配-捆绑器2,Ruby 2.6

时间:2019-01-10 07:35:03

标签: ruby-on-rails ruby bundler ruby-2.6

我们刚刚将ruby更新为2.6,并将bundler更新为2。现在,我们得到:

# bin/rails console
You must use Bundler 2 or greater with this lockfile.

以前在bundle exec中发生过这种情况:

# bundle exec rails console
You must use Bundler 2 or greater with this lockfile.

那时,默认情况下,我们仍在运行1.17.2:

# gem list bundler

*** LOCAL GEMS ***

bundler (2.0.1, default: 1.17.2)

因此我们运行了gem uninstall bundler --version 1.17.2,然后bundle exec开始工作。

但是bin之类的bin/rails存根仍然失败。

1.17.2在卸载后如何运行?

5 个答案:

答案 0 :(得分:6)

您的答案中的诊断似乎正确。但似乎您可以通过在gem install bundler行之前添加 来激活最新安装的Bundler gem(由require 'bundler/setup'安装):

Gem::Specification.find_by_name('bundler').activate

如果需要,也可以使用更具体的版本要求。例如:

Gem::Specification.find_by_name('bundler', '~> 2.0.1').activate
如果找不到该宝石,

find_by_name会引发LoadError派生的异常。

答案 1 :(得分:5)

好的,我想我们已经解决了。

事实证明,Ruby是通过安装捆绑程序来“捆绑”的。在我们的情况下,它存储在所有标准库内容旁边的/usr/local/lib/ruby/2.6.0/中。该版本显然是捆绑程序的1.17.2。

如果我们运行bundle exec,则不会使用该版本,因为它(在我们的设置中)调用可执行文件/usr/local/bundle/bin/bundle-使用2.0.1的rubygems安装。

但是,调用bin/rails或类似的binstub不会发生这种情况。这些捆绑程序生成的存根的行如下:

require_relative '../config/boot'

好的,听起来不错。 config/boot.rb然后执行:

require 'bundler/setup'

看起来也无害。但这不会影响rubygems的安装。我想可能不行吗?因为这是捆绑程序要设置$LOAD_PATH的那行,以便实际上将使用捆绑程序中指定的宝石。

因此,它不会显示捆绑程序(2.0.1)的rubygems安装,而是会显示标准库安装(1.17.2)。哪个吓到了,因为它可以看到Gemfile.lock太新了。

这个怪胎显然只是从v2捆绑器开始的。如果它是在1.17.2的Gemfile.lock上运行的bundler的1.16,则不在乎。因此,过去大概没有较老的标准库捆绑软件就可以了。

但是现在。因此,我想提出三种可能的补救措施:

  • 在您使用标准库中捆绑程序v2随附的Ruby版本之前,请勿将捆绑程序升级到v2。
  • 请执行升级捆绑程序,但不要使用binstub,而应使用bundle exec
  • 安装后删除标准库捆绑程序:rm -rf /usr/local/lib/ruby/2.6.0/bundler*。显然,这对我们似乎很有效,YMMV。

(如果捆绑程序必须在标准库中进行引导,则不知道为什么最后一种可行。)

无论如何,希望能在类似情况下帮助他人节省一些时间。

答案 2 :(得分:1)

您尝试过(ruby 2.6)

import matplotlib.pyplot as plt
import numpy as np
import random

nrows = 2
ncols = 3
# Create the subplot array
fig, (axes) = plt.subplots(nrows=nrows, ncols=ncols, figsize=(10, 6), 
                           dpi=300, sharex=True, sharey=True)
for i in range(nrows):
    for j in range(ncols):
        a = np.arange(10)
        x, y = np.meshgrid(a, a)
        z = np.random.randint(0, 7, (10, 10))
        im = axes[i][j].contourf(x, y, z)
        # Remove the tick marks but leave the superleft and superbottom alone
        if i != nrows-1:
            if j != 0:
                axes[i][j].tick_params(axis='both', which='both', 
                           left=False, bottom=False, top=False)
            else:
                axes[i][j].tick_params(axis='both', which='both', bottom=False, top=False)
        else:
            if j != 0:
                axes[i][j].tick_params(axis='both', which='both', left=False, top=False)
fig.tight_layout()
# Some additional whitespace adjustment is needed
fig.subplots_adjust(right=0.825, hspace=0.025, wspace=0.025)
cax = fig.add_axes([0.85, 0.06, 0.035, 0.91])
fig.colorbar(im, cax=cax)
plt.show()

答案 3 :(得分:1)

如果有的话,这可能是邦德勒本身的问题。

尝试以下步骤:

  • 删除现有的Gemfile.lock

  • 更新Rubygems:

    gem update --system

  • 重新生成Binstubs版本

    bundle binstubs bundler

  • 捆绑安装

    bundle install

使用bundle exec [command]来运行

答案 4 :(得分:0)

捆绑器版本可能已写入binstubs。使用bundle binstubs GEM_NAME重新生成它们,它应该可以工作。