Re: [External] re: Adding a directory to LOAD_PATH
"Tran, Minh" <[email protected]> Thu, 7 Nov 2019 19:05:07 +0000
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <SN6PR05MB5391526F655EBE84D5A2E416EE780@SN6PR05MB5391.namprd05.prod.outlook.com> |
--===============1098895472== Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_SN6PR05MB5391526F655EBE84D5A2E416EE780SN6PR05MB5391namp_" --_000_SN6PR05MB5391526F655EBE84D5A2E416EE780SN6PR05MB5391namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thank you so much Leam for all of the helps. It works. Regards, Minh ________________________________ From: ruby-talk <[email protected]> on behalf of Leam Hall <l= [email protected]> Sent: Thursday, November 7, 2019 1:52 PM To: Ruby users <[email protected]> Subject: Re: [External] re: Adding a directory to LOAD_PATH Try putting ".." before "/vendor", do not have a space between "expand_path" and the "(", and use File.expand_path instead of FILE.expand_path. This worked for me: ruby -e '$LOAD_PATH << File.expand_path("../lib/", __FILE__)' Leam On 11/7/19 1:46 PM, Tran, Minh wrote: > I got an error message when I tried to use LOAD_PATH. I would like to > seek your helps and expertise. > > Thanks! > > ruby -e '$LOAD_PATH << FILE.expand_path > ("/vendor/kinectic-sdk-rb",__FILE__)' > > - syntax error, unexpected ( arg, expecting end-of-input > ...LOAD_PATH << FILE.expand_path ("vendor/kinectic.. > > > ------------------------------------------------------------------------ > *From:* ruby-talk <[email protected]> on behalf of Leam > Hall <[email protected]> > *Sent:* Thursday, November 7, 2019 12:53 PM > *To:* Ruby users <[email protected]> > *Subject:* Re: [External] re: Adding a directory to LOAD_PATH > Hey, since you're new to Ruby, I'll point you to one of the secrets: > irb. It gives you a live Ruby environment to try things out. I'm new to > Ruby too, and irb helps me learn. Here's an example: > > [leam@shaphan ruby]$ pwd; ls lib > /home/leam/lang/ruby > shot_string.rb > > [leam@shaphan ruby]$ irb > > irb(main):001:0> require 'shot_string' > Traceback (most recent call last): > 6: from /usr/local/bin/irb:23:in `<main>' > 5: from /usr/local/bin/irb:23:in `load' > 4: from > /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.1.0.pre.3/exe/irb:11:in `<top > (required)>' > 3: from (irb):1 > 2: from > /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in > `require' > 1: from > /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in > `require' > LoadError (cannot load such file -- shot_string) > > irb(main):002:0> $LOAD_PATH << File.expand_path("../lib/", __FILE__) > > =3D> ["/usr/local/lib/ruby/gems/2.7.0/gems/did_you_mean-1.3.1/lib", > "/usr/local/lib/ruby/site_ruby/2.7.0", > "/usr/local/lib/ruby/site_ruby/2.7.0/x86_64-linux", > "/usr/local/lib/ruby/site_ruby", > "/usr/local/lib/ruby/vendor_ruby/2.7.0", > "/usr/local/lib/ruby/vendor_ruby/2.7.0/x86_64-linux", > "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby/2.7.0", > "/usr/local/lib/ruby/2.7.0/x86_64-linux", "/home/leam/lang/ruby/lib"] > > irb(main):003:0> require 'shot_string' > =3D> true > irb(main):004:0> > > > Leam > > > > > On 11/7/19 12:41 PM, Tran, Minh wrote: >> Thank you so much Leam. >> I would like to load the kinetic-sdk.rb program in >> /vendor/kinetic-sdk-rb/ to my current working directory /my_project ; >> so would the following command work ? >> >> $LOAD_PATH << File.expand_path("/vendor/kinectic-sdk-rb", __FILE__) >> ------------------------------------------------------------------------ >> *From:* ruby-talk <[email protected]> on behalf of Leam >> Hall <[email protected]> >> *Sent:* Thursday, November 7, 2019 12:16 PM >> *To:* Ruby users <[email protected]> >> *Subject:* Re: [External] re: Adding a directory to LOAD_PATH >> Have you tried something like: >> >> $LOAD_PATH << File.expand_path("../my_project/", __FILE__) >> >> That's what I usually do, with "../lib". >> >> Leam >> >> >> On 11/7/19 11:55 AM, Tran, Minh wrote: >>> >>> Thank you so much Raj for all of the helps. >>> Since I am new to Ruby, could I ask on how could I add my project vendo= r >>> directory to the load path ? >>> >>> I did a ruby -e 'puts $LOADPATH' command , and it gave me my current >>> LOAD_PATH >>> >>> /usr/local/lib/site_ruby/2.3.0 >>> /usr/local/lib/x86_64-linux-gnu/site_ruby >>> /usr/local/lib/site_ruby >>> /usr/lib/ruby/vendor_ruby/2.3.0 >>> /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0 >>> /usr/lib/ruby/vendor_ruby >>> /usr/lib/ruby/2.3.0 >>> /usr/lib/x86_64-linux-gnu/ruby/2.3.0 >>> >>> I am still googling for a Ruby command that I could use to add my vendo= r >>> folder to the LOAD_PATH. >>> >>> Thanks for all of the helps, >>> Minh >>> >>> >>> -----------------------------------------------------------------------= - >>> *From:* ruby-talk <[email protected]> on behalf of Raj >>> Sahae <[email protected]> >>> *Sent:* Wednesday, November 6, 2019 5:54 PM >>> *To:* Ruby users <[email protected]> >>> *Subject:* [External] Re: Could not load a Ruby program >>> This is sort of a strange thing to do. You are using require while >>> dynamically generating the path based on the location of test.rb, which >>> could change with respect to your vendor directory. >>> Your error message would seem to indicate that the relative path of >>> kinetic-sdk.rb from test.rb is not what you are specifying. >>> >>> If you want to use kinetic-sdk.rb as a library file, then the folder yo= u >>> want to load it from should be in your load path. >>> There are a couple ways to do this but in my opinion the easiest to tes= t >>> with is using "ruby -I" >>> >>> So if I were you, I would keep kinetic-sdk.rb where it is, and add your >>> projects vendor directory to the load path, and then call require in >>> test.rb with that relative path. >>> >>> test.rb would be something like >>> >>> *#!/usr/bin/ruby >>> * >>> *puts "Hello World!" >>> * >>> *require 'kinectic-sdk-rb/kinectic-sdk.rb'* >>> * >>> * >>> And you would run it with a command like >>> >>> ruby -I my_project/vendor test.rb >>> >>> You can persist that sort of thing by setting your RUBYLIB env variable= , >>> or changing load_path inside your test.rb, etc. There are many ways. >>> >>> >>> -Raj >>> >>> >>> On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <[email protected]= g >>> <mailto:[email protected]>> wrote: >>> >>> Hello, >>> >>> I have a scenario that I need to execute a program from the >>> other directory than my current directory. >>> I got an error when I ran it, and I would like to seek helps >>> and expertises. >>> >>> >>> My current directory is at my_project, and the program that >>> I would like to execute is >>> at my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb >>> >>> In my current directory my_project, I have a test.rb which contain= s >>> a very simple line of code such as >>> >>> #!/usr/bin/ruby >>> puts "Hello World!" >>> require File.join (File.expand_path (File.dirname(__FILE__)), >>> 'vendor/kinectic-sdk-rb/kinectic-sdk.rb') >>> >>> >>> I tried to run the test.rb at my current directory which >>> is my_project , and I got the following error message: >>> >>> Could not load file kinectic-sdk.rb from >>> my /my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb folder. >>> >>> >>> Thanks for all of your helps, >>> Minh >>> >>> >> >> >> Unsubscribe: <mailto:[email protected]?subject=3Dunsubscri= be> >> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> >> >> ------------------------------------------------------------------------ >> >> This e-mail message (including any attachments) is for the sole use of >> the intended recipient(s) and may contain confidential and privileged >> information. If the reader of this message is not the intended >> recipient, you are hereby notified that any dissemination, distribution >> or copying of this message (including any attachments) is strictly >> prohibited. >> >> If you have received this message in error, please contact >> the sender by reply e-mail message and destroy all copies of the >> original message (including attachments). > > > Unsubscribe: <mailto:[email protected]?subject=3Dunsubscrib= e> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> --_000_SN6PR05MB5391526F655EBE84D5A2E416EE780SN6PR05MB5391namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > <style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo= ttom:0;} </style> </head> <body dir=3D"ltr"> <div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san= s-serif; font-size: 12pt;"> Thank you so much Leam for all of the helps. It works.</div> <div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san= s-serif; font-size: 12pt;"> Regards,</div> <div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san= s-serif; font-size: 12pt;"> Minh</div> <div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san= s-serif; font-size: 12pt;"> <br> </div> <div id=3D"appendonsend"></div> <hr style=3D"display:inline-block;width:98%" tabindex=3D"-1"> <div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st= yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> ruby-talk <ruby-ta= [email protected]> on behalf of Leam Hall <[email protected]&= gt;<br> <b>Sent:</b> Thursday, November 7, 2019 1:52 PM<br> <b>To:</b> Ruby users <[email protected]><br> <b>Subject:</b> Re: [External] re: Adding a directory to LOAD_PATH</font> <div> </div> </div> <div class=3D"BodyFragment"><font size=3D"2"><span style=3D"font-size:11pt;= "> <div class=3D"PlainText">Try putting ".." before "/vendor&qu= ot;, do not have a space between <br> "expand_path" and the "(", and use File.expand_path ins= tead of <br> FILE.expand_path.<br> <br> This worked for me:<br> <br> ruby -e '$LOAD_PATH << File.expand_path("../l= ib/", __FILE__)'<br> <br> Leam<br> <br> <br> On 11/7/19 1:46 PM, Tran, Minh wrote:<br> > I got an error message when I tried to use LOAD_PATH. I would lik= e to <br> > seek your helps and expertise.<br> > <br> > Thanks!<br> > <br> > ruby -e '$LOAD_PATH << FILE.expand_path <br> > ("/vendor/kinectic-sdk-rb",__FILE__)'<br> > <br> > - syntax error, unexpected ( arg, expecting end-of-input<br> > ...LOAD_PATH << FILE.expand_path ("vendor/kinectic..<br> > <br> > <br> > ----------------------------------------------------------------------= --<br> > *From:* ruby-talk <[email protected]> on behalf of= Leam <br> > Hall <[email protected]><br> > *Sent:* Thursday, November 7, 2019 12:53 PM<br> > *To:* Ruby users <[email protected]><br> > *Subject:* Re: [External] re: Adding a directory to LOAD_PATH<br> > Hey, since you're new to Ruby, I'll point you to one of the secrets:<b= r> > irb. It gives you a live Ruby environment to try things out. I'm new t= o<br> > Ruby too, and irb helps me learn. Here's an example:<br> > <br> > [leam@shaphan ruby]$ pwd; ls lib<br> > /home/leam/lang/ruby<br> > shot_string.rb<br> > <br> > [leam@shaphan ruby]$ irb<br> > <br> > irb(main):001:0> require 'shot_string'<br> > Traceback (most recent call last):<br> > 6: from /usr/lo= cal/bin/irb:23:in `<main>'<br> > 5: from /usr/lo= cal/bin/irb:23:in `load'<br> > 4: from<br> > /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.1.0.pre.3/exe/irb:11:in `<= ;top<br> > (required)>'<br> > 3: from (irb):1= <br> > 2: from<br> > /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in<br= > > `require'<br> > 1: from<br> > /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in<br= > > `require'<br> > LoadError (cannot load such file -- shot_string)<br> > <br> > irb(main):002:0> $LOAD_PATH << File.expand_path("../lib/= ", __FILE__)<br> > <br> > =3D> ["/usr/local/lib/ruby/gems/2.7.0/gems/did_you_mean-1.3.1/= lib",<br> > "/usr/local/lib/ruby/site_ruby/2.7.0",<br> > "/usr/local/lib/ruby/site_ruby/2.7.0/x86_64-linux",<br> > "/usr/local/lib/ruby/site_ruby",<br> > "/usr/local/lib/ruby/vendor_ruby/2.7.0",<br> > "/usr/local/lib/ruby/vendor_ruby/2.7.0/x86_64-linux",<br> > "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby= /2.7.0",<br> > "/usr/local/lib/ruby/2.7.0/x86_64-linux", "/home/leam/l= ang/ruby/lib"]<br> > <br> > irb(main):003:0> require 'shot_string'<br> > =3D> true<br> > irb(main):004:0><br> > <br> > <br> > Leam<br> > <br> > <br> > <br> > <br> > On 11/7/19 12:41 PM, Tran, Minh wrote:<br> >> Thank you so much Leam.<br> >> I would like to load the kinetic-sdk.rb program in <br> >> /vendor/kinetic-sdk-rb/ to my current working directory= /my_project ;<br> >> so would the following command work ?<br> >> <br> >> $LOAD_PATH << File.expand_path("/vendor/kinectic-sdk-rb= ", __FILE__)<br> >> ------------------------------------------------------------------= ------<br> >> *From:* ruby-talk <[email protected]> on behal= f of Leam <br> >> Hall <[email protected]><br> >> *Sent:* Thursday, November 7, 2019 12:16 PM<br> >> *To:* Ruby users <[email protected]><br> >> *Subject:* Re: [External] re: Adding a directory to LOAD_PATH<br> >> Have you tried something like:<br> >> <br> >> $LOAD_PATH << File.expand_pat= h("../my_project/", __FILE__)<br> >> <br> >> That's what I usually do, with "../lib".<br> >> <br> >> Leam<br> >> <br> >> <br> >> On 11/7/19 11:55 AM, Tran, Minh wrote:<br> >>> <br> >>> Thank you so much Raj for all of the helps.<br> >>> Since I am new to Ruby, could I ask on how could I add my proj= ect vendor <br> >>> directory to the load path ?<br> >>> <br> >>> I did a ruby -e 'puts $LOADPATH' command , and it gave me my c= urrent <br> >>> LOAD_PATH<br> >>> <br> >>> /usr/local/lib/site_ruby/2.3.0<br> >>> /usr/local/lib/x86_64-linux-gnu/site_ruby<br> >>> /usr/local/lib/site_ruby<br> >>> /usr/lib/ruby/vendor_ruby/2.3.0<br> >>> /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0<br> >>> /usr/lib/ruby/vendor_ruby<br> >>> /usr/lib/ruby/2.3.0<br> >>> /usr/lib/x86_64-linux-gnu/ruby/2.3.0<br> >>> <br> >>> I am still googling for a Ruby command that I could use t= o add my vendor <br> >>> folder to the LOAD_PATH.<br> >>> <br> >>> Thanks for all of the helps,<br> >>> Minh<br> >>> <br> >>> <br> >>> --------------------------------------------------------------= ----------<br> >>> *From:* ruby-talk <[email protected]> on b= ehalf of Raj <br> >>> Sahae <[email protected]><br> >>> *Sent:* Wednesday, November 6, 2019 5:54 PM<br> >>> *To:* Ruby users <[email protected]><br> >>> *Subject:* [External] Re: Could not load a Ruby program<br> >>> This is sort of a strange thing to do. You are using require w= hile <br> >>> dynamically generating the path based on the location of test.= rb, which <br> >>> could change with respect to your vendor directory.<br> >>> Your error message would seem to indicate that the relative pa= th of <br> >>> kinetic-sdk.rb from test.rb is not what you are specifying.<br= > >>> <br> >>> If you want to use kinetic-sdk.rb as a library file, then the = folder you <br> >>> want to load it from should be in your load path.<br> >>> There are a couple ways to do this but in my opinion the easie= st to test <br> >>> with is using "ruby -I"<br> >>> <br> >>> So if I were you, I would keep kinetic-sdk.rb where it is, and= add your <br> >>> projects vendor directory to the load path, and then call requ= ire in <br> >>> test.rb with that relative path.<br> >>> <br> >>> test.rb would be something like<br> >>> <br> >>> *#!/usr/bin/ruby<br> >>> *<br> >>> *puts "Hello World!"<br> >>> *<br> >>> *require 'kinectic-sdk-rb/kinectic-sdk.rb'*<br> >>> *<br> >>> *<br> >>> And you would run it with a command like<br> >>> <br> >>> ruby -I my_project/vendor test.rb<br> >>> <br> >>> You can persist that sort of thing by setting your RUBYLIB env= variable, <br> >>> or changing load_path inside your test.rb, etc. There are many= ways.<br> >>> <br> >>> <br> >>> -Raj<br> >>> <br> >>> <br> >>> On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <minh.tran@emoryh= ealthcare.org <br> >>> <<a href=3D"mailto:[email protected]">mailto:mi= [email protected]</a>>> wrote:<br> >>> <br> >>> Hello,<br> >>> <br> >>> I have a scen= ario that I need to execute a program from the<br> >>> other directory than my current direct= ory.<br> >>> I got an error when I ran it, and I wo= uld like to seek helps<br> >>> and expertises.<br> >>> <br> >>> <br> >>> My current directory is at my_project,= and the program that<br> >>> I would like to execute= is<br> >>> at my_project/vendor/kinectic-sdk= -rb/kinectic-sdk.rb<br> >>> <br> >>> In my current directory my_project, I = have a test.rb which contains<br> >>> a very simple line of code such as<br> >>> <br> >>> #!/usr/bin/ruby<br> >>> puts "Hello World!"<br> >>> require File.join (File.expand_path (F= ile.dirname(__FILE__)),<br> >>> 'vendor/kinectic-sdk-rb/kinectic-sdk.r= b')<br> >>> <br> >>> <br> >>> I tried to run the test.rb at my curre= nt directory which<br> >>> is my_project , and I got the fol= lowing error message:<br> >>> <br> >>> Could not load file kinectic-sdk.= rb from<br> >>> my /my_project/vendor/kinec= tic-sdk-rb/kinectic-sdk.rb folder.<br> >>> <br> >>> <br> >>> Thanks for all of your helps,<br> >>> Minh<br> >>> <br> >>> <br> >> <br> >> <br> >> Unsubscribe: <<a href=3D"mailto:[email protected]= ?subject=3Dunsubscribe">mailto:[email protected]?subject=3Dun= subscribe</a>><br> >> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/= ruby-talk">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>= ><br> >> <br> >> ------------------------------------------------------------------= ------<br> >> <br> >> This e-mail message (including any attachments) is for the sole us= e of<br> >> the intended recipient(s) and may contain confidential and privile= ged<br> >> information. If the reader of this message is not the intended<br> >> recipient, you are hereby notified that any dissemination, distrib= ution<br> >> or copying of this message (including any attachments) is strictly= <br> >> prohibited.<br> >> <br> >> If you have received this message in error, please contact<br> >> the sender by reply e-mail message and destroy all copies of the<b= r> >> original message (including attachments).<br> > <br> > <br> > Unsubscribe: <<a href=3D"mailto:[email protected]?sub= ject=3Dunsubscribe">mailto:[email protected]?subject=3Dunsubs= cribe</a>><br> > <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby= -talk">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>>= <br> <br> <br> Unsubscribe: <<a href=3D"mailto:[email protected]?subject= =3Dunsubscribe">mailto:[email protected]?subject=3Dunsubscrib= e</a>><br> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk= ">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>><br> </div> </span></font></div> </body> </html> --_000_SN6PR05MB5391526F655EBE84D5A2E416EE780SN6PR05MB5391namp_-- --===============1098895472== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> --===============1098895472==--