5

Set up the Ruby environment with RVM or rbenv in Mac

Hello, I'm new to Ruby and OpenStudio measure development. I have a question upon how to set up the environment of OpenStudio library for Ruby in Mac.

Currently I'm running Ruby through rvm(Ruby Version Manager) which is a stand alone ruby directory so that I won't mess up with the System Ruby. Here's what I did: First I ran gem install openstudio to get the library installed. After that I ran require "openstudio" in the IRB, the error message prints:

LoadError: cannot load such file -- openstudioutilitiescore

My ruby version in the rvm is 2.0.0p643 and OpenStudio v. 1.7.5.

Any help would be appreciated!

-----------------------------------------------------------------------------------------------------------------------------------------------------

Thanks David.

Here is what I did after:

I created the openstudio.rb file with the content:

require '/Applications/OpenStudio 1.7.5/Ruby/openstudio.rb'

And then saved it to:

/Users/my_user_name/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/

Then I uninstalled the openstudio package (which I install with gem earlier)

I tried to run require "openstudio" again in the irb.

The reports prints:

-- Crash Report log information -------------------------------------------- See Crash Report log file under the one of following: * ~/Library/Logs/CrashReporter * /Library/Logs/CrashReporter * ~/Library/Logs/DiagnosticReports * /Library/Logs/DiagnosticReports the more detail of.

-- Control frame information ----------------------------------------------- c:0027 p:-17572663487022 s:0124 e:000123 TOP [FINISH] c:0026 p:---- s:0122 e:000121 CFUNC :require c:0025 p:0113 s:0118 e:000117 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/siteruby/2.0.0/rubygems/coreext/kernelrequire.rb:54 c:0024 p:0476 s:0108 e:000107 TOP /Applications/OpenStudio 1.7.5/Ruby/openstudio.rb:86 [FINISH] c:0023 p:---- s:0102 e:000101 CFUNC :require c:0022 p:0113 s:0098 e:000097 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/siteruby/2.0.0/rubygems/coreext/kernelrequire.rb:54 c:0021 p:0007 s:0088 e:000087 TOP /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/siteruby/openstudio.rb:1 [FINISH] c:0020 p:---- s:0086 e:000085 CFUNC :require c:0019 p:0113 s:0082 e:000081 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/siteruby/2.0.0/rubygems/coreext/kernelrequire.rb:54 c:0018 p:0007 s:0072 e:000071 EVAL (irb):1 [FINISH] c:0017 p:---- s:0070 e:000069 CFUNC :eval c:0016 p:0024 s:0063 e:000062 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/irb/workspace.rb:86 c:0015 p:0025 s:0056 e:000054 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/irb/context.rb:380 c:0014 p:0022 s:0050 e:000049 BLOCK /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/irb.rb:492 c:0013 p:0040 s:0042 e:000041 METHOD /Users/YJ/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/irb.rb:624 c:0012 p:0009 s:0037 e:000036 BLOCK /Users ...
(more)
yiyuan-jia's avatar
218
yiyuan-jia
asked 2015-06-15 17:26:27 -0500
Neal Kruis's avatar
4.7k
Neal Kruis
updated 2015-07-24 16:39:50 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

14

I think the issue is around the lack of the Ruby shared-libraries when using RVM (or rbenv).

For RVM, when you install the ruby, make sure to pass in the config flag for 'enable-shared'

rvm install 2.0.0 -C --enable-shared

If you use rbenv, then you need to export the environment variable

RUBY_CONFIGURE_OPTS=--enable-shared rbenv install 2.0.0-p353

You should then be able to do:

irb -I <path-to-openstudio.rb>

e.g. irb -I /Application/OpenStudio\ 1.7.5/Ruby/

I prefer to set an environment variable that points to my version of OpenStudio. In my .bash_profile, I add:

export RUBYLIB="/Applications/OpenStudio 1.7.5/Ruby"

long's avatar
409
long
answered 2015-06-18 10:26:32 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks Nick, what does the --enable-shared do?

macumber's avatar macumber (2015-06-18 11:59:29 -0500) edit

That solves the problem. Thanks Nick!

yiyuan-jia's avatar yiyuan-jia (2015-06-18 13:37:05 -0500) edit
1

It builds the shared libraries for Ruby which are needed for linking by OpenStudio. For Linux it builds the libruby.so and for Mac the libruby.dylib.

long's avatar long (2015-06-18 15:06:57 -0500) edit
add a comment see more comments
-3

If you want to use OpenStudio's ruby API outside of our GUI's you need to tell your system ruby where to find OpenStudio.

Create a file with this content.

require 'C:\Program Files\OpenStudio 1.7.0\Ruby\openstudio.rb'

Place it in your system ruby's site folder at a path similar to this.

C:\Ruby200\lib\ruby\site_ruby\openstudio.rb

Also, the openstudio gem isn't something you should typically use. You just need OpenStudio installed, and optionally ruby (you can use your system ruby, or you can use OpenStudio's installed ruby).

Update: Just found this described in more detail in the measure testing section of our measure writing guide.

David Goldwasser's avatar
20.4k
David Goldwasser
answered 2015-06-16 11:23:26 -0500, updated 2015-06-16 11:26:57 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments