ruby, rails gem install error - ERROR: While executing gem ... (Encoding::UndefinedConversionError) - ruby

I tried with last version with ruby, but when run gem install rails, always got an error
ERROR: While executing gem ... (Encoding::UndefinedConversionError)
U+041D to IBM437 in conversion from UTF-16LE to UTF-8 to IBM437
I am using windows 8.
but gem list ---local working.. only on install, my locale set english.
what kind problem is it?

Use this link:
https://bugs.ruby-lang.org/issues/10300
They said that you need to chance the enconding at The registry.rb file:
Folder: Ruby2.1.0\lib\ruby\2.1.0\win32
File: registry.rb
Line: 70
- LOCALE = Encoding.find(Encoding.locale_charmap)
+ LOCALE = Encoding::UTF_8
+ #LOCALE = Encoding.find(Encoding.locale_charmap)

We'll need more information to solve your problem. What command are you running?
The meaning of the exception is that some character in the gem is invalid in ibm437, a common 'extended ascii' encoding on Windows machines.
You may be to work around the problem by setting your internal encoding to UTF-8. Encoding.default_internal = Encoding::UTF_8
Would you mind adding the output a running a ruby file containing just the following:
p [Encoding.default_external, Encoding.default_internal, __ENCODING__, Encoding.find('filesystem'), Encoding.find('locale')]
Thanks. If you only do it in irb that's fine to.

Related

Issue installing ceedling in Windows 11

I have tried to install ceedling for Windows 11. But come across this error:
Failed to load C:/ProgramData/gemrc, (<unknown>): control characters are not allowed at line 1 column 1
I installed Ruby 3.1.3.1 (x64) from here https://rubyinstaller.org/downloads/
Then I ran:
gem install ceedling
Any ideas on how to install ceedling correctly would be appreciated.
That error is telling you that the file C:\ProgramData\gemrc has invalid data in it at line 1, column 1. You have most likely edited this file improperly when installing Ruby because this is a default file with a default configuration that should have been created when you installed Ruby.
You should try these steps in order:
Inspect the file to see what invalid characters exist at that position, comparing it to some default gemrc files, and remove any invalid characters, or:
Rename the file and try again, or:
Remove the file and reinstall Ruby from scratch so that the file is created from scratch

Windows gem install error: extconf.rb:301:in `assert_has_dev_libs!': invalid byte sequence in UTF-8 (ArgumentError)

I am new to ruby and wanted to add responsive images to my site. I decided to use jekyll-responsive-image. When the install gave me issues, I installed ImageMagick, thinking it was a dependency, following this. Then tried to install rmagick (assuming it is also a dependency) using both
gem install rmagick -v '4.1.2' --source 'https://rubygems.org/'
and
gem install rmagick --platform=ruby -- --with-opt-lib='C:/ImageMagick-7.0.10-Q16-HDRI/lib' --with-opt-include='C:/ImageMagick-7.0.10-Q16-HDRI/include'
The output of these are
checking for Ruby version >= 2.3.0... yes
checking for magick... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include=${opt-dir}/include
--with-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby27-x64/bin/$(RUBY_BASE_NAME)
extconf.rb:301:in `assert_has_dev_libs!': invalid byte sequence in UTF-8 (ArgumentError)
from extconf.rb:267:in `assert_can_compile!'
from extconf.rb:18:in `initialize'
from extconf.rb:395:in `new'
from extconf.rb:395:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/rmagick-4.1.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rmagick-4.1.2 for inspection.
The log does not look helpful
assert_minimum_ruby_version!: checking for Ruby version >= 2.3.0... -------------------- yes
--------------------
find_executable: checking for magick... -------------------- yes
--------------------
It looks like the invalid byte sequence error is stopping me from installing any new gems. Based on other questions on stack overflow, I've tried to check that my path does not contain any specially characters. From this post, I set the user environment variables of LANG, LANGUAGE, and LC_ALL to en_US.UTF-8, and LC_CTYPE to C.BINARY. RUBYOPT is set to -Eutf-8.
How can I solve this error? Keep in mind I'm on Windows 10. Thank you
I just ran into this.
When installing rmagick, the extconf.rb file is running the magick command at the command prompt and running a regex on the output to check the version number. You can reproduce this issue easily by making a simple ruby file with the following content (copied from extconf.rb):
`magick --version` =~ /Version: ImageMagick (\d+\.\d+\.\d+)-+\d+ /
Run this file, and you'll see the same invalid byte sequence exception. We can verify this like so:
str = `magick --version`
str.valid_encoding? # false
From inspecting the output of that magick command on the command prompt, it looks like the version output uses the © symbol (\xA9), which appears to be throwing the exception.
I had an old imagemagick installer lying around (~2 months old) which used a simple C instead of © in the copyright output, and that version of imagemagick seems to allow rmagick to install properly. You may want to dig around for an older installer and see if this resolves your issue.

Encoding issues with Ruby-2.4.1

I am having different output of following line with different version of ruby:
puts "#{"%c"%[254]}"
Output from ruby-2.4.1 : þ
Output from ruby-1.8.7 : �
It looks like issue with encoding, as there is no encoding in Ruby-1.8.7
Can someone please help me to get same result as Ruby-1.8.7 in Ruby-2.4.1 also?
This result is desirable because Ruby-1.8.7 gives me "254" after decoding while Ruby-2.4.1 gives me following error
`%': invalid value for Integer(): "þ" (ArgumentError)
I don't know much about Ruby 1.8.7, as I started Ruby with version 2.3, but this looks promising: https://gist.github.com/afair/2911107
But as everyone else is saying it would be best to upgrade your Ruby version if at all possible. Older versions of Ruby had limited Unicode support.

Why could `rb_sysopen` not be found anymore by the custom fact since the upgrade to Puppet4?

The following custom fact:
# returns latest packerversion, e.g. 0.10.1
Facter.add("latest_packerversion") do
setcode do
url="https://www.packer.io/downloads.html"
file = open("#{url}")
contents = file.read()
match = contents.match(/Latest\sversion:\s(.*)</)
match[1]
end
end
worked using puppet 3.6.2, but since the upgrade to 4.5.2 the following issue occurs:
Error: Facter: error while resolving custom fact "latest_packerversion":
No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
Analysis
It seems that the rb_sysopen could not be found anymore for some reason (No such file or directory # rb_sysopen) since the upgrade to Puppet 4.
Puppet4 seems to use an embedded ruby version instead of the one installed on the host (Puppet3):
Puppet 4, both Facter 2.4 and CFacter 0.4, the latest Hiera and
Mcollective, as well Ruby 2.1.5, OpenSSL 1.0.0r, and our gem
dependencies.
Does rb_sysopen not exist in Ruby 2.1.5? No evidence was found.
Perhaps a change related to facts have occurred that could cause the issue? Nothing related was found in the release notes.
Question
Why could rb_sysopen not be found anymore by the custom fact since the upgrade to Puppet4?
Concise
I will include require 'open-uri' in both facts, but I do not understand why this is required since the upgrade to Puppet4
Verbose
Once require 'open-uri' is included in one of the custom facts the issue is solved.
# returns latest gitversion, e.g. 2.8.2
Facter.add("latest_gitversion") do
setcode do
require 'open-uri'
url="https://git-scm.com/downloads"
file = open("#{url}")
contents = file.read()
match = contents.match(/RelNotes.*((\d\.){2}\d)/)
match[1]
end
end
As soon as the require 'open-uri' has been commented out, the issue occurs again:
Error: Facter: error while resolving custom fact "latest_gitversion": No such file or directory # rb_sysopen - https://git-scm.com/downloads
Error: Facter: error while resolving custom fact "latest_packerversion": No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
At the moment it is unclear what is causing the issue.

Ruby PDFLib on OSX: LoadError in require

I just downloaded and installed the Ruby for OSX version of PDFLib (from pdflib.com).
I am using the following setup:
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.4.0]
OSX Yosemite 10.10.4
PDFLib 9.0.5
The require 'PDFLib' statement in my Ruby file produces the following error message:
/Users/[...]/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require': dlsym(0x7ff6e3ef4b90, Init_PDFLib): symbol not found - [...]/PDFLib.bundle (LoadError)
So it seems that the Ruby interpreter cannot find the Init_PDFLib in the library. But from the output of nm I gather that this symbol seems to be present:
$ nm -g ./PDFlib.bundle | grep -i init
0000000000001200 T _Init_PDFlib
[...]
Has anyone any idea what goes wrong? Thanks in advance for your answers.
Found it!
The PDFlib file is called PDFlib.bundle (small l), and my code did a require 'PDFLib' (capitalized L).
It turns out that the require does load the bundle file regardless of the wrong capitalization, but then searches for the Init_PDFLib symbol, which is not present.
So changing the require statement to require 'PDFlib' (small l) worked.

Resources