ruby 在 Windows 7 上“无法构建 gem 本机扩展”(系统找不到指定的路径)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20688671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Failed to build gem native extension' on Windows 7 (The system cannot find the path specified)
提问by dannysmith
The problem in short
问题简而言之
I'm on Windows and am getting the following error when running gem install json —platform=ruby:
我在 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
Background and some Investigations
背景和一些调查
So first off, I'm not a Windows person so this is a brave new world for me. Having inherited a laptop from work that had a mad collection of libraries spread all over it I've managed to remove all previous installations of ruby and the Devkit and then installed the following:
首先,我不是 Windows 人,所以这对我来说是一个美丽的新世界。从工作中继承了一台笔记本电脑,里面到处都是疯狂的库集合,我设法删除了所有以前安装的 ruby 和 Devkit,然后安装了以下内容:
- Ruby 1.9.3p484 with Ruby Installerinto
C:/Ruby193 - Ruby 2.0.0p353 with Ruby Installerinto
C:/Ruby200 - Devkit
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe(for ruby 1x) extracted intoC:/Ruby193-devkit - Devkit
DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe(32-bit for ruby 2x) extracted intoC:/Ruby200-devkit-x32.
- 红宝石1.9.3p484与红宝石安装成
C:/Ruby193 - 红宝石2.0.0p353与红宝石安装成
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(32 位用于 ruby 2x)提取到C:/Ruby200-devkit-x32.
I then installed Pik 0.2.8as a gem and ran pik_installinto a new directory C:/binas per the installation instructions.
然后我将Pik 0.2.8作为 gem安装并按照安装说明运行pik_install到一个新目录C:/bin。
My PATH looks like this:
我的路径如下所示:
PATH=C:\bin;C:\Ruby193\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\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
The important things being that C:/binand C:/Ruby193/binare in the path. This means that ruby 1.9.3 is loaded by default when I fire up a shell and I can successfully switch to 2.0.0 with pik use 2.0.0p353. In other words, pik works fine.
重要的事情是,C:/bin并且C:/Ruby193/bin在路上。这意味着当我启动 shell 时默认加载 ruby 1.9.3 并且我可以使用pik use 2.0.0p353. 换句话说,pik 工作正常。
Devkit is intendedto allow the compiling of native C/C++ binaries from gems on Windows, so as to aviod using precompiled windows binaries.
Devkit旨在允许从 Windows 上的 gems 编译本机 C/C++ 二进制文件,从而避免使用预编译的 Windows 二进制文件。
Because I've got two versions of ruby installed, and each requires a different devkit (one for 2x and one for 1x), I had to do the setup for devkit twice:
因为我安装了两个版本的 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
At this point I should have been able to run gem install json —platform=rubysuccessfully, but got the error above. After a little digging I discovered this, which advises checking that COMSPEC is set corectly and removing any AutoRun keys from HKEY_CURRENT_USER\Software\Microsoft\Command Processor– I had one from ANSIcon and duly deleted it.
此时我应该能够gem install json —platform=ruby成功运行,但出现了上述错误。经过一番挖掘,我发现了这一点,它建议检查 COMSPEC 是否正确设置并从中删除任何 AutoRun 键HKEY_CURRENT_USER\Software\Microsoft\Command Processor——我从 ANSIcon 中获得了一个并适当删除了它。
Unfortunatly I was still unable to install the json gem.
不幸的是,我仍然无法安装 json gem。
It then struck me that perhaps the wrong version of GCC was being used, or not being found. The two versions of Devkit come with different versions of gcc:
然后我突然意识到可能使用了错误版本的 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
I then wondered if pik wasn't loading the version of devtools (and therefore gcc) for the specific version of ruby that i'd picked, and was always using 1.9.3. Thanks to this article, it seems that's not the case:
然后我想知道 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'
(I don't actually have cat available on windows but it makes for a clearer explanation)
(我实际上在 Windows 上没有 cat 可用,但它可以提供更清晰的解释)
As you can see, it looks like the correct version of devkit is being added to the path by devkit.rb, which is obviously being loaded because my error contains 'Temporarily enhancing PATH to include DevKit…'.
如您所见,devkit.rb 似乎正在将正确版本的 devkit 添加到路径中,这显然正在加载,因为我的错误包含“临时增强 PATH 以包含 DevKit...”。
Back to the original error
回到原来的错误
It was:
它是:
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
Unfortunatly the results log doesn't exactly offer much in the way of help. This is what gem_make.out looks like:
不幸的是,结果日志并没有提供太多帮助。这是 gem_make.out 的样子:
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
I thought that extconf.rbmight offer some help, but I can't make head nor tail of it:
我认为这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'
The Makefile in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generatorlooks like this. It seems odd to me that this Makefile is even being created.
中的 MakefileC:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator看起来像这样。对我来说,这个 Makefile 甚至正在被创建似乎很奇怪。
If anybody with a bit more Windows/Ruby experience can shed any light on this it would be amazing!
如果有更多 Windows/Ruby 经验的人可以对此有所了解,那就太棒了!
PS. I'm on Windows 7 Professional SP1
附注。我使用的是 Windows 7 Professional SP1
Update after some more digging
更多挖掘后更新
So I wanted to check that devkit was defiantly enhancing the path with the correct devkit directories. Thanks to a suggestion from another SO question, I moved the devkit installations inside the Ruby directories:
所以我想检查一下 devkit 是否使用正确的 devkit 目录大胆地增强了路径。感谢另一个 SO 问题的建议,我将 devkit 安装移到了 Ruby 目录中:
The tdm devkit now lives in C:\Ruby193\devkitwhile the mingw64 lives in C:\Ruby200\devkit. Having run ruby dk.rb install -ffor each devkit, I opened up both devkit.rb files to check that the path's had been updated correctly. They had, and I updated the puts so it should print "Temporarily enhancing PATH do include DevKit for 1.9" or "Temporarily enhancing PATH do include DevKit for 2". By way of confirmation that the correct devkit is being loaded:
tdm devkit 现在位于C:\Ruby193\devkitmingw64 中,而 mingw64 位于C:\Ruby200\devkit. ruby dk.rb install -f为每个 devkit运行后,我打开了两个 devkit.rb 文件以检查路径是否已正确更新。他们有,我更新了看跌期权,所以它应该打印“临时增强 PATH 包括 DevKit for 1.9”或“临时增强 PATH 包括 DevKit for 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 Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\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 Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\Tools\Binn\;c:\Program Files\Microsoft SQL Server0\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
So that all looks like it works correctly. but:
这样一切看起来都可以正常工作。但:
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
This clearly tells us two things:
这清楚地告诉我们两件事:
- Some other devkit.rb file is being loaded when I'm using ruby 1.9, as the 'for 1.9' message isn't being printed.
- This is unlikely to be the actual problem, as the error is identical in either case.
- 当我使用 ruby 1.9 时,正在加载其他一些 devkit.rb 文件,因为没有打印“for 1.9”消息。
- 这不太可能是实际问题,因为两种情况下的错误都是相同的。
I'm going to see if I can build manually using the generated Makefiles.
我将看看是否可以使用生成的 Makefile 手动构建。
回答by dannysmith
So this isn't the best answer in the world, but I seem to have stumbled on a solution. If I set the verbose flag, everything works fine:
所以这不是世界上最好的答案,但我似乎偶然发现了一个解决方案。如果我设置了详细标志,一切正常:
gem install json --platform=ruby --verbose
There's a log here: http://gist.github.com/dannysmith/8055495
这里有一个日志:http: //gist.github.com/dannysmith/8055495
That makes no sense - it'd be great if someone could explain why this seems to have fixed the error. Perhaps this is a bug in devkit?
这是没有意义的 - 如果有人能解释为什么这似乎修复了错误,那就太好了。也许这是 devkit 中的一个错误?
回答by obesechicken13
Try running command prompt in admin mode. After like 7-10 hours I figured this out...
尝试在管理员模式下运行命令提示符。大约 7-10 个小时后,我发现了这一点......
回答by Swapnil Kotwal
I have gem json installed with versions 1.8.1 but I was not able to solve this issue for json 1.6.1 using
我已经安装了 1.8.1 版的 gem json,但是我无法使用 json 1.6.1 解决这个问题
gem install json --platform=ruby --verbose
So, I tried from here https://github.com/oneclick/rubyinstaller/issues/184
所以,我从这里尝试https://github.com/oneclick/rubyinstaller/issues/184
gem update --system 2.0.3
And after that
在那之后
gem install json -v 1.6.1 --platform=ruby --verbose
It solve issue specific to json 1.6.1 for Win 7(64 bit) machine
它解决了 Win 7(64 位)机器的 json 1.6.1 特有的问题
回答by codeslapper
Install the 32 bit version on Windows...
在 Windows 上安装 32 位版本...
ver
windows 6.1.76011
64 bit gave error message about makefile and headers. Tried all other suggestions including those on rubyinstaller about COMSPEC and registry, adding gcc to path, and others. Some gems would install but git_fame and json would not as needed to compile.
64 位给出了关于 makefile 和 headers 的错误消息。尝试了所有其他建议,包括 rubyinstaller 上关于 COMSPEC 和注册表的建议,将 gcc 添加到路径等。一些 gems 会安装,但 git_fame 和 json 不需要编译。
Edit: It looks like git_fame uses mimer_plus. mimer_plus assumes gnu tools (unix tools). Looks like you need to install mingw first. That was not clearly indicated on the rubyinstaller page.
编辑:看起来 git_fame 使用 mimer_plus。mimer_plus 假定使用 gnu 工具(unix 工具)。看起来你需要先安装mingw。这在 rubyinstaller 页面上没有明确指出。
回答by EarlLamont
I had the same problem. I used powershell to check my path
我有同样的问题。我用powershell来检查我的路径
ps> $s = $env:path
ps> $s.split("{;}")
ps> $s = $env:path
ps> $s.split("{;}")
sure enough my the ruby mingw was not in the path. I had the ruby\bin in the path but the mingw\bin was under a different folder. I went into my environment path and added it and my install worked.
果然我的 ruby mingw 不在路径中。我在路径中有 ruby\bin 但 mingw\bin 在不同的文件夹下。我进入我的环境路径并添加它并且我的安装工作。
回答by Mosab Sasi
Make sure that the ruby version you installed (32 or 64 bit) matches the DevKit version. They both have to be 32 or 64, which was the issue I was having. May not be the exact issue here, but thought I'd throw that out there. Here's a post worth checking out:
确保您安装的 ruby 版本(32 位或 64 位)与 DevKit 版本匹配。他们都必须是 32 或 64,这是我遇到的问题。可能不是这里的确切问题,但我想我会把它扔在那里。这是一个值得一看的帖子:
回答by Garry Gomez
How I fixed it:
我是如何修复它的:
- Downloaded the latest ruby installer from https://rubyinstaller.org/downloads/
- Ran the installer, following the prompts to install dependencies.
- Restarted my computer.
- Added the ruby/bin directory to my PATH.
- 从https://rubyinstaller.org/downloads/下载最新的 ruby 安装程序
- 运行安装程序,按照提示安装依赖项。
- 重新启动了我的电脑。
- 将 ruby/bin 目录添加到我的 PATH。

