Re: Could not load a Ruby program
Raj Sahae <[email protected]> Wed, 6 Nov 2019 14:54:59 -0800
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAJHnM_6r+9C95eFO-1mTFrtKqwREZ9a+MP+POC+f2ToKfDQFYQ@mail.gmail.com> |
--===============0063536863== Content-Type: multipart/alternative; boundary="000000000000e5c5360596b57033" --000000000000e5c5360596b57033 Content-Type: text/plain; charset="UTF-8" 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 you 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 test 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]> 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 contains 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 > > > > > ------------------------------ > *From:* ruby-talk <[email protected]> on behalf of Dan > Fitzpatrick <[email protected]> > *Sent:* Friday, October 25, 2019 12:30 AM > *To:* [email protected] <[email protected]> > *Subject:* [External] Re: How to compare a hash key with a string value > > Hello Dun, > > > First I would change the name of your variable "hash" to something else > because it is not a hash, it is an array of hashes. Since it represents > a list of people, I would call it people. > > > The main issue is that your keys are getting converted to symbols. So > none of the objects have the "width" attribute as a string. > > > This is the only thing that continuously annoys me about Ruby: > > > a = > {"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step > > 1","width":"100%"} > > => {:label=>"Name", :value=>"Bob", :identifier=>"field2", > :type=>"oneLineText", :page=>1, :page_name=>"Step 1", :width=>"100%"} > > > b > ={"label"=>"Name","value"=>"Bob","identifier"=>"field2","type"=>"oneLineText","page"=>1,"page_name"=>"Step > > 1","width"=>"100%"} > => {"label"=>"Name", "value"=>"Bob", "identifier"=>"field2", > "type"=>"oneLineText", "page"=>1, "page_name"=>"Step 1", "width"=>"100%"} > > a['width'] > > => nil > > b['width'] > > => "100%" > > a[:width] > > => "100%" > > > Here is your code working: > > people = > [{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step > > 1","width":"100%"},{"label":"Email","value":"[email protected]","identifier":"field3","type":"email","page":1,"page_name":"Step > > 1","width":"100%"},{"label":"Phone > Number","value":"","identifier":"field7","type":"oneLineText","page":1,"page_name":"Step > > 1","width":"100%"},{"label":"Comments","value":"some information about > the > compagny","identifier":"field5","type":"textarea","page":1,"page_name":"Step > > 1","width":"100%"}] > > > # If you only need the width attribute, you can do this (no loop on the > attributes needed): > > people.each_with_index do |person, i| > puts "Person is #{i+1}" # First person displays as 1 instead of 0 > > puts "The value of width is #{person[:width]}" if > person.has_key?(:width) > end > > > # If needed, loop through all the attributes of person (like in your > example), but change to detecting symbol keys > > people.each_with_index do |person, i| > puts "Person is #{i+1}" # First person is 1 instead of 0 > > person.each do |key, value| > if key == :width > puts "The value of width is #{value}" > end > end > end > > > Also, if you are defining your hashes, you don't need to use JSON format > with quoted keys, you can just do: > > a = {label: "Name", value: "Bob", identifier: "field2", type: > "oneLineText", page: 1, page_name: "Step 1", width: "100%"} > > > Dan > > > On 10/24/2019 1:35 AM, Tran, Minh wrote: > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe > <[email protected]?subject=unsubscribe>> > <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=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > --000000000000e5c5360596b57033 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">This is sort of a strange thing to do. You are using requi= re while dynamically generating the path based on the location of test.rb, = which could change with respect to your vendor directory.<div>Your error me= ssage would seem to indicate that the relative path of kinetic-sdk.rb from = test.rb is not what you are specifying.</div><div><br></div><div>If you wan= t to use kinetic-sdk.rb as a library file, then the folder you want to load= it from should be in your load path.</div><div>There are a couple ways to = do this but in my opinion the easiest to test with is using "ruby -I&q= uot;</div><div><br></div><div>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.</div><div><br></div><= div>test.rb would be something like</div><div><font face=3D"arial, sans-ser= if"><br></font></div><div><div style=3D"color:rgb(0,0,0)"><font face=3D"ari= al, sans-serif"><b>#!/usr/bin/ruby<br></b></font></div><div style=3D"color:= rgb(0,0,0)"><font face=3D"arial, sans-serif"><b>puts "Hello World!&quo= t;<br></b></font></div><div style=3D"color:rgb(0,0,0)"><font face=3D"arial,= sans-serif" style=3D""><b>require 'kinectic-sdk-rb/kinectic-sdk.rb'= ;</b></font></div><div style=3D"color:rgb(0,0,0)"><font face=3D"arial, sans= -serif" style=3D""><b><br></b></font></div><div style=3D"color:rgb(0,0,0)">= <font face=3D"arial, sans-serif">And you would run it with a command like</= font></div><div style=3D"color:rgb(0,0,0)"><font face=3D"arial, sans-serif"= ><br></font></div><div style=3D"color:rgb(0,0,0)"><font face=3D"arial, sans= -serif">ruby -I=C2=A0</font><span style=3D"color:rgb(34,34,34)">my_project/= vendor test.rb</span></div><br class=3D"gmail-Apple-interchange-newline"></= div><div>You can persist that sort of thing by setting your RUBYLIB env var= iable, or changing load_path inside your test.rb, etc. There are many ways.= </div><div><br></div><div><div><br clear=3D"all"><div><div dir=3D"ltr" clas= s=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div>-Raj</div></d= iv></div><br></div></div></div><br><div class=3D"gmail_quote"><div dir=3D"l= tr" class=3D"gmail_attr">On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <<a h= ref=3D"mailto:[email protected]">[email protected]<= /a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0= px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir=3D"ltr"> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> Hello, </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> =C2=A0=C2=A0=C2=A0 I have a scenario that I=C2=A0need to execute a program = from the other directory than my current directory.</div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> I got an error when I ran it, and I would like to seek helps and=C2=A0exper= tises.</div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> My current directory is at my_project, and=C2=A0the=C2=A0program that I=C2= =A0would=C2=A0like=C2=A0to execute is at=C2=A0my_project/vendor/kinectic-sd= k-rb/kinectic-sdk.rb </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> In my current directory my_project, I have=C2=A0 a test.rb which contains a= very simple line of code such as </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span>#!/usr/bin/ruby<br> </span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> puts "Hello World!"<br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span>require File.join (File.expand_path (File.dirname(__FILE__)), 've= ndor/kinectic-sdk-rb/kinectic-sdk.rb')</span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span><br> </span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span><br> </span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span>I tried to run the test.rb at my current directory=C2=A0which is=C2= =A0my_project , and I got the following error message:</span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span><br> </span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <span>Could not load=C2=A0file kinectic-sdk.rb=C2=A0 from my=C2=A0=C2=A0/my= _project/vendor/kinectic-sdk-rb/kinectic-sdk.rb folder.=C2=A0</span></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> Thanks for all of your helps,</div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> Minh</div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <div> <div id=3D"gmail-m_3084731617864670336appendonsend"></div> <div style=3D"color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-ser= if;font-size:12pt"> <br> </div> <hr style=3D"width:98%;display:inline-block"> <div id=3D"gmail-m_3084731617864670336divRplyFwdMsg" dir=3D"ltr"><font colo= r=3D"#000000" face=3D"Calibri, sans-serif" style=3D"font-size:11pt"><b>From= :</b> ruby-talk <<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a>> on behalf of Dan Fitz= patrick <<a href=3D"mailto:[email protected]" target=3D"_blank">dan@epar= klabs.com</a>><br> <b>Sent:</b> Friday, October 25, 2019 12:30 AM<br> <b>To:</b> <a href=3D"mailto:[email protected]" target=3D"_blank">rub= [email protected]</a> <<a href=3D"mailto:[email protected]" tar= get=3D"_blank">[email protected]</a>><br> <b>Subject:</b> [External] Re: How to compare a hash key with a string valu= e</font> <div>=C2=A0</div> </div> <div><font size=3D"2"><span style=3D"font-size:11pt"> <div>Hello Dun,<br> <br> <br> First I would change the name of your variable "hash" to somethin= g else <br> because it is not a hash, it is an array of hashes. Since it represents <br= > a list of people, I would call it people.<br> <br> <br> The main issue is that your keys are getting converted to symbols. So <br> none of the objects have the "width" attribute as a string.<br> <br> <br> This is the only thing that continuously annoys me about Ruby:<br> <br> <br> a =3D <br> {"label":"Name","value":"Bob","= ;identifier":"field2","type":"oneLineText&quo= t;,"page":1,"page_name":"Step <br> 1","width":"100%"}<br> <br> =3D> {:label=3D>"Name", :value=3D>"Bob", :iden= tifier=3D>"field2", <br> :type=3D>"oneLineText", :page=3D>1, :page_name=3D>"= Step 1", :width=3D>"100%"}<br> <br> <br> b <br> =3D{"label"=3D>"Name","value"=3D>"= Bob","identifier"=3D>"field2","type"= =3D>"oneLineText","page"=3D>1,"page_name&quo= t;=3D>"Step <br> 1","width"=3D>"100%"}<br> =3D> {"label"=3D>"Name", "value"=3D>= "Bob", "identifier"=3D>"field2", <br> "type"=3D>"oneLineText", "page"=3D>1, &= quot;page_name"=3D>"Step 1", "width"=3D>&quo= t;100%"}<br> <br> a['width']<br> <br> =3D> nil<br> <br> b['width']<br> <br> =3D> "100%"<br> <br> a[:width]<br> <br> =3D> "100%"<br> <br> <br> Here is your code working:<br> <br> people =3D <br> [{"label":"Name","value":"Bob",&quo= t;identifier":"field2","type":"oneLineText&qu= ot;,"page":1,"page_name":"Step <br> 1","width":"100%"},{"label":"Email&= quot;,"value":"<a href=3D"mailto:[email protected]" target=3D= "_blank">[email protected]</a>","identifier":"field3&quo= t;,"type":"email","page":1,"page_name&qu= ot;:"Step <br> 1","width":"100%"},{"label":"Phone = <br> Number","value":"","identifier":"fi= eld7","type":"oneLineText","page":1,&quo= t;page_name":"Step <br> 1","width":"100%"},{"label":"Commen= ts","value":"some information about <br> the <br> compagny","identifier":"field5","type":&= quot;textarea","page":1,"page_name":"Step <br= > 1","width":"100%"}]<br> <br> <br> # If you only need the width attribute, you can do this (no loop on the <br= > attributes needed):<br> <br> people.each_with_index do |person, i|<br> =C2=A0=C2=A0 puts "Person is #{i+1}" # First person displays as 1= instead of 0<br> <br> =C2=A0=C2=A0 puts "The value of width is #{person[:width]}" if pe= rson.has_key?(:width)<br> end<br> <br> <br> # If needed, loop through all the attributes of person (like in your <br> example), but change to detecting symbol keys<br> <br> people.each_with_index do |person, i|<br> =C2=A0=C2=A0 puts "Person is #{i+1}" # First person is 1 instead = of 0<br> <br> =C2=A0=C2=A0 person.each do |key, value|<br> =C2=A0=C2=A0=C2=A0=C2=A0 if key =3D=3D :width<br> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 puts "The value of width is #{val= ue}"<br> =C2=A0=C2=A0=C2=A0=C2=A0 end<br> =C2=A0=C2=A0 end<br> end<br> <br> <br> Also, if you are defining your hashes, you don't need to use JSON forma= t <br> with quoted keys, you can just do:<br> <br> a =3D {label: "Name", value: "Bob", identifier: "f= ield2", type: <br> "oneLineText", page: 1, page_name: "Step 1", width: &qu= ot;100%"}<br> <br> <br> Dan<br> <br> <br> On 10/24/2019 1:35 AM, Tran, Minh wrote:<br> <br> Unsubscribe: <<a href=3D"mailto:[email protected]?subject= =3Dunsubscribe" target=3D"_blank">mailto:[email protected]?su= bject=3Dunsubscribe</a>><br> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk= " target=3D"_blank">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby= -talk</a>><br> </div> </span></font></div> </div> <br> <hr> <font face=3D"Arial" color=3D"Gray" size=3D"1"><br> This e-mail message (including any attachments) is for the sole use of<br> the intended recipient(s) and may contain confidential and privileged<br> information. If the reader of this message is not the intended<br> recipient, you are hereby notified that any dissemination, distribution<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<br> original message (including attachments).<br> </font> </div> <br> Unsubscribe: <mailto:<a href=3D"mailto:[email protected]" = target=3D"_blank">[email protected]</a>?subject=3Dunsubscribe= ><br> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk= " rel=3D"noreferrer" target=3D"_blank">http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-talk</a>><br> </blockquote></div> --000000000000e5c5360596b57033-- --===============0063536863== 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> --===============0063536863==--