Ruby ';未能生成gem本机扩展';在Windows 7上(系统找不到指定的路径) 简而言之,这个问题
我在Windows上,运行Ruby ';未能生成gem本机扩展';在Windows 7上(系统找不到指定的路径) 简而言之,这个问题,ruby,windows,pik,Ruby,Windows,Pik,我在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:
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,带into
C:/Ruby193
- Ruby 2.0.0p353,带into
C:/Ruby200
- Devkit
(用于ruby 1x)提取到Devkit-tdm-32-4.5.2-20111229-1559-sfx.exe
C:/Ruby193 Devkit
- Devkit
(ruby 2x为32位)提取到Devkit-mingw64-32-4.7.2-20130224-1151-sfx.exe
C:/Ruby200-Devkit-x32
pik_install
运行到一个新目录C:/bin
我的路径如下所示:
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
成功切换到2.0.0。换句话说,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是否正确设置,并从HKEY\U CURRENT\u 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添加到路径中,显然正在加载该路径,因为我的错误包含“临时增强路径以包含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'
所以看起来一切都正常。但是:
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
这清楚地告诉我们两件事:
我将看看是否可以使用生成的makefile手动构建。因此这不是世界上最好的答案,但我似乎偶然发现了一个解决方案。如果我设置了详细标志,一切正常:
gem install json --platform=ruby --verbose
这里有一个日志:
这毫无意义——如果有人能解释为什么这似乎已经修复了错误,那就太好了。也许这是devkit中的一个bug?尝试在管理模式下运行命令提示符。大约7-10个小时后,我发现了这一点…我已经在1.8.1版中安装了gem json,但我无法使用
gem install json --platform=ruby --verbose
所以,我试着从这里开始
然后呢
gem install json -v 1.6.1 --platform=ruby --verbose
它解决了Win 7(64位)机器json 1.6.1特有的问题在Windows上安装32位版本
ver
windows 6.1.76011
64位给出了有关makefile和标头的错误消息。尝试了所有其他建议,包括rubyinstaller上关于COMSPEC和registry的建议、将gcc添加到path的建议,以及其他建议。一些gems会安装,但git_fame和json不会根据需要编译
编辑:看起来git_fame使用了mimer_plus。mimer_plus采用gnu工具(unix工具)。看起来您需要先安装mingw。rubyinstaller页面上没有明确指出这一点。我也有同样的问题。我使用powershell检查我的路径 ps>$s=$env:path ps>$s.split(“{;}”)
果不其然,我的红宝石不在路上。我在路径中有ruby\bin,但mingw\bin在另一个文件夹下。我进入我的环境路径并添加了它,我的安装工作正常。确保您安装的ruby版本(32或64位)与DevKit版本匹配。他们都必须是32或64岁,这是我遇到的问题。可能不是这里的问题,但我想我会把它扔出去。这里有一篇文章值得一看: 我是如何修复的:
真是一场噩梦!我只是把Windows和OSX放在了一起。是的,我在虚拟机上运行了mint发行版。我不喜欢将它用于开发,但它只是让事情变得更容易。现在切换到Mac太晚了。我正在安装Rails,尽管我的错误消息是关于
extconf.rb
和缺少unistd.h
,但这个答案完全解决了我的问题。这样做有冲突吗?这对我来说很管用,但这不会导致以后没有权限
gem install json -v 1.6.1 --platform=ruby --verbose
ver
windows 6.1.76011