20

简而言之问题

我在 Windows 上运行时出现以下错误gem install json —platform=ruby

The system cannot find the path specified.
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
The system cannot find the path specified.
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

背景和一些调查

所以首先,我不是 Windows 用户,所以这对我来说是一个勇敢的新世界。从工作中继承了一台笔记本电脑,那里到处都是疯狂的库集合,我设法删除了所有以前安装的 ruby​​ 和 Devkit,然后安装了以下内容:

  • Ruby 1.9.3p484 与Ruby 安装程序进入C:/Ruby193
  • Ruby 2.0.0p353 与Ruby 安装程序进入C:/Ruby200
  • Devkit DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe(用于 ruby​​ 1x)提取到C:/Ruby193-devkit
  • Devkit DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe(Ruby 2x 的 32 位)提取到C:/Ruby200-devkit-x32.

然后我将Pik 0.2.8安装为 gem,并按照安装说明运行pik_install到一个新目录。C:/bin

我的 PATH 如下所示:

PATH=C:\bin;C:\Ruby193\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Support\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64

重要的事情就是这样,C:/bin并且C:/Ruby193/bin在路上。这意味着当我启动 shell 时默认加载 ruby​​ 1.9.3,我可以使用pik use 2.0.0p353. 换句话说, pik 工作正常。

Devkit旨在允许从 Windows 上的 gems 编译本机 C/C++ 二进制文件,以避免使用预编译的 windows 二进制文件。

因为我安装了两个版本的 ruby​​,每个版本都需要不同的 devkit(一个用于 2x,一个用于 1x),我必须为 devkit 设置两次:

cd C:/Ruby193-devkit
ruby dk.rb init
# Edit config.yml to remove all but Ruby193
ruby dk.rb install

cd C:/Ruby200-devkit
ruby dk.rb init
# Edit config.yml to remove all but C:/Ruby200
ruby dk.rb install

此时我应该已经能够gem install json —platform=ruby成功运行了,但是得到了上面的错误。经过一番挖掘,我发现了这一点,它建议检查 COMSPEC 是否正确设置并从中删除任何 AutoRun 键HKEY_CURRENT_USER\Software\Microsoft\Command Processor——我从 ANSIcon 中获得了一个并适当地删除了它。

不幸的是,我仍然无法安装 json gem。

然后让我感到震惊的是,可能使用了错误的 GCC 版本,或者没有找到。两个版本的 Devkit 带有不同版本的 gcc:

> C:\Ruby193-devkit\mingw\bin\gcc —version
gcc (tdm-1) 4.5.2

> C:\Ruby200-devkit-x32\mingw\bin\gcc —version
gcc (rubenv-4.7.2-release) 4.7.2

然后我想知道 pik 是否没有为我选择的特定版本的 ruby​​ 加载 devtools 版本(以及因此 gcc),并且始终使用 1.9.3。感谢这篇文章,看来情况并非如此:

> pik use 193
> where ruby
C:\Ruby193\bin\ruby.exe

> cat C:\Ruby193\lib\ruby\site_ruby\devkit.rb
# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\Ruby193-devkit\\mingw\\bin') then
  puts 'Temporarily enhancing PATH to include DevKit...'
  ENV['PATH'] = 'C:\\Ruby193-devkit\\bin;C:\\Ruby193-devkit\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\Ruby193-devkit'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'


> pik use 200
> where ruby
C:\Ruby200\bin\ruby.exe

> cat C:\Ruby200\lib\ruby\site_ruby\devkit.rb
# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\Ruby200-devkit-x32\\mingw\\bin') then
  phrase = 'Temporarily enhancing PATH to include DevKit...'
  if defined?(Gem)
    Gem.ui.say(phrase) if Gem.configuration.verbose
  else
    puts phrase
  end
  puts "Prepending ENV['PATH'] to include DevKit..." if $DEBUG
  ENV['PATH'] = 'C:\\Ruby200-devkit-x32\\bin;C:\\Ruby200-devkit-x32\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\Ruby200-devkit-x32'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'

(我实际上在 Windows 上没有 cat 可用,但它可以提供更清晰的解释)

如您所见,devkit.rb 似乎正在将正确版本的 devkit 添加到路径中,这显然正在加载,因为我的错误包含“临时增强 PATH 以包含 DevKit...”。

回到原来的错误

它是:

The system cannot find the path specified.
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
The system cannot find the path specified.
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

不幸的是,结果日志并没有提供太多帮助。这就是 gem_make.out 的样子:

C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile

我认为这extconf.rb可能会提供一些帮助,但我无法理解它:

require 'mkmf'

unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
  $CFLAGS << ' -O3'
end
if CONFIG['CC'] =~ /gcc/
  $CFLAGS << ' -Wall'
  unless $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
    $CFLAGS << ' -O0 -ggdb'
  end
end

$defs << "-DJSON_GENERATOR"
create_makefile 'json/ext/generator'

中的 MakefileC:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator 看起来像这样。对我来说,这个 Makefile 甚至正在被创建似乎很奇怪。

如果有更多 Windows/Ruby 经验的人能对此有所了解,那就太棒了!

PS。我使用的是 Windows 7 Professional SP1

更多挖掘后更新

因此,我想检查 devkit 是否使用正确的 devkit 目录明显地增强了路径。感谢另一个 SO question 的建议,我将 devkit 安装移到了 Ruby 目录中:

tdm devkit 现在存在,C:\Ruby193\devkit而 mingw64 存在于C:\Ruby200\devkit. 为每个 devkit运行后ruby dk.rb install -f,我打开了两个 devkit.rb 文件以检查路径是否已正确更新。他们有,我更新了 puts,所以它应该打印“临时增强 PATH 确实包括 DevKit for 1.9”或“临时增强 PATH 确实包括 DevKit 2”。通过确认正在加载正确的 devkit:

C:\>pik 193

C:\>ruby -rdevkit -ve "puts ENV['PATH']"
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
Temporarily enhancing PATH to include DevKit for 1.9...
C:\Ruby193\devkit\bin;C:\Ruby193\devkit\mingw\bin;C:\bin;C:\Ruby193\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)
\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Pro
gram Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Su
pport\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin
;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\sy
swow64

C:\>pik 200

C:\>ruby -rdevkit -ve "puts ENV['PATH']"
ruby 2.0.0p353 (2013-11-22) [i386-mingw32]
Temporarily enhancing PATH to include DevKit for 2...
C:\Ruby200\devkit\bin;C:\Ruby200\devkit\mingw\bin;C:\bin;C:\Ruby200\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)
\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Pro
gram Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Su
pport\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin
;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\sy
swow64

这样看起来一切正常。但:

C:\>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit for 2...
Building native extensions.  This could take a while...
The system cannot find the path specified.
ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb
creating Makefile


Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

C:\>pik 193

C:\>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
The system cannot find the path specified.
ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

这清楚地告诉我们两件事:

  1. 当我使用 ruby​​ 1.9 时,正在加载其他一些 devkit.rb 文件,因为没有打印“for 1.9”消息。
  2. 这不太可能是实际问题,因为在任何一种情况下错误都是相同的。

我将看看是否可以使用生成的 Makefile 手动构建。

4

7 回答 7

12

所以这不是世界上最好的答案,但我似乎偶然发现了一个解决方案。如果我设置详细标志,一切正常:

gem install json --platform=ruby --verbose

这里有一个日志:http: //gist.github.com/dannysmith/8055495

这没有任何意义——如果有人能解释为什么这似乎已经修复了错误,那就太好了。也许这是devkit中的一个错误?

于 2013-12-20T14:30:33.743 回答
7

尝试在管理员模式下运行命令提示符。大约 7-10 小时后,我想通了...

于 2014-03-19T01:20:14.017 回答
7

我安装了 1.8.1 版本的 gem json,但我无法使用 json 1.6.1 解决这个问题

gem install json --platform=ruby --verbose

所以,我从这里尝试了https://github.com/oneclick/rubyinstaller/issues/184

gem update --system 2.0.3

在那之后

gem install json -v 1.6.1 --platform=ruby --verbose

它解决了 Win 7(64 位)机器的 json 1.6.1 特有的问题

于 2014-04-10T07:57:15.347 回答
0

确保您安装的 ruby​​ 版本(32 位或 64 位)与 DevKit 版本匹配。他们都必须是 32 或 64,这是我遇到的问题。可能不是这里的确切问题,但我想我会把它扔在那里。这是一个值得一看的帖子:

Windows上的Rails - 安装问题

于 2017-04-19T21:46:08.293 回答
0

我如何修复它:

  1. 从https://rubyinstaller.org/downloads/下载了最新的 ruby​​ 安装程序
  2. 运行安装程序,按照提示安装依赖项。
  3. 重新启动了我的电脑。
  4. 将 ruby​​/bin 目录添加到我的 PATH 中。
于 2017-12-21T17:42:03.423 回答
0

在 Windows 上安装 32 位版本...

ver
windows 6.1.76011

64 位给出了关于 makefile 和 headers 的错误信息。尝试了所有其他建议,包括关于 COMSPEC 和注册表的 ruby​​installer 建议,将 gcc 添加到路径等。一些 gem 会安装,但 git_fame 和 json 不会按需要进行编译。

编辑:看起来 git_fame 使用 mimer_plus。mimer_plus 假定使用 gnu 工具(unix 工具)。看起来你需要先安装mingw。rubyinstaller 页面上没有明确指出。

于 2015-10-06T18:36:26.600 回答
0

我有同样的问题。我使用 powershell 检查我的路径

ps> $s = $env:路径

ps> $s.split("{;}")

果然,我的 ruby​​ mingw 不在路上。我在路径中有 ruby​​\bin,但 mingw\bin 在不同的文件夹下。我进入我的环境路径并添加它并且我的安装工作。

于 2015-11-29T18:49:41.153 回答