Is there a well-designed method that can run my ruby program from anywhere? I already searched a couple of ways to import my ruby program from the different directories by using the relative path.
i.e.
File.expand_path(“my_path”)
It worked and let me run it anywhere, but somehow, it is a little unreadable and I think it is pretty messy. So I think there may be a solution or convention to deal with this kind of problem when there are many file paths that have to be imported.
I suggest you have a look how to package a gem and build your own and install it. Or you could place your binary in $PATH, but that's a bit more messy.
Related
I am currently attempting to install the tensorflow object detection app on Windows 7 (employer requirement) and I am failing at a few steps from the end.
Basically I get the following error when I run the installation test command:
ImportError: No module named nets.
I have read some solutions on the subject:
https://github.com/tensorflow/models/issues/729
https://github.com/tensorflow/models/issues/1842
which looks like this:
export PYTHONPATH="$PYTHONPATH:"somepath"/tensorflow/models/slim"
basically meaning that I must set the right path in the PYTHONPATH environmental variable.
Working with Windows, I tried calling this:
SET PYTHONPATH="$PYTHONPATH:C:tensorflow/models/slim
And when it didn't work, I created a PYTHONPATH variable in system-> environmental variables.
I'm still getting the error so I suppose that I am still missing something but due to my lack of knowledge I still can't figure out what.
Would someone familiar with Windows be able to point out what's missing?
Thanks
in linux:
add export export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim to ~/.bashrc
attention:you should keep single quote mark
if you work with windows, i guess it should like this:PYTHONPATH=$PYTHONPATH:'C:/tensorflow/models':'C:/tensorflow/models'/slim
just my guess, you can take a try.
good luck!
If you run the setup.py it will install all the relevant modules for object detection. The other option is download the git directory. cd to the folder and try to run the module from there. You might face protubuf issue. Try to install it before running the code. It's bit complicated to install protobuf in windows. But if you are not using ".pb" file, then you don't need to.
I figured out a way to make it work. I am not writing this as a final answer as it is mostly a workaround and due to lack of understanding from my part I cannot guarantee it will work (and also it might not be best good practice).
Anyway here it is:
As Beta previously suggested, you have to run setup.py, however running it from models folder did not do it for me, I also had to run it from object detection folder.
However there was a problem there, it generated an error saying the BUILD already existed (which was correct) so I had to delete the BUILD file from inside of model.
After that it worked, turns out the path I had set was working fine.
Now if some experts would look into this and explain how and why this workaround worked it might make this a valid solution.
I have two isolated Ruby installations (one for Chef, one for Sensu). From within the Chef installation, I'd like to get a list of all versions of a gem installed into the Sensu ruby. I know the absolute paths of both installations at runtime.
I've used Gem::Specification::find_all_by_name before to great effect, and this is the sort of method I'm looking for, but it only seems to work on the currently executing ruby, and doesn't seem to have any kind of notion of reusability.
One way would be to use gem list with grep and parse that output, but i'd really rather not have to shell out to solve the problem, I prefer an in-ruby solution. I could also inspect the filesystem myself and recreate the logic of Gem::Specification, but that's not that much better than shelling out.
Is there a way to get equivalent output to Gem::Specification without duplicating the parsing logic myself?
Gem::Specification has a (global) property called dirs which allows you to specify an array of paths that Gem::Specification will use when searching for specifications.
Note that the path it expects must be the parent folder of "specifications", so for instance /opt/embedded/product/lib/specifications will not work, but /opt/embedded/product/lib will work.
Is the process of creating a custom command/plugin, such as pg:transfer ( for example ) documented somewhere? I tried searching for this kind of info but I get no relevant results.
Unfortunately there is not much in the way of docs around that. Your best bet is to review examples and go from there. The key is basically that whatever is in init.rb there will be loaded, so you can simply define your additions there (or require the files that define them if it is a larger/more complex plugin). The end result just ends up monkey-patching the toolbelt, so you can also look at toolbelt commands for additional examples. Finally, if you need any external gems you will need to use vendored copies of them. Hope that helps put you on the right track, but let me know if you have further questions.
After years of being away from Ruby, I'm back full-force and have just cut my first gem, which includes an executable. Everything works like a charm.
The problem I am facing, however, is that I ALSO have a startup script (not part of the gem istelf) that daemonizes the executable. Additionally, I'd also like for the startup script to point the executable at configuration in a place like /var/
To the best of my knowledge, there's no way with rubygems, gemspec, etc., to specify files getting blown out to other parts of your system during install (e.g. startup script to /etc/init.d, and config to /var/). It certainly wouldn't make sense if you COULD do that.
So... my question is... what IS the proper procedure for automating the installation of something like this. I'm using RHEL, and am wondering if it's, perhaps, time for me to get my feet wet with making my first RPM.
Any thoughts?
You can do it. However it is probably not quite the recommended approach. But yes it is possible to run arbitary code during gem installation using the extensions option.
From the RubyGems Manual:
Usage
spec.extensions << 'ext/rmagic/extconf.rb'
Notes
These files will be run when the gem is installed, causing the
C (or whatever) code to be compiled on the user’s machine.
Just place whatever ruby code you need into the extconf.rb (or equivalent) file.
Examples for building C-extensions from the RubyGems Guides:
http://guides.rubygems.org/c-extensions/
I've got a project for work I'd like to do in Ruby that will have to run on Windows, but perturbing the filesystem for a Ruby install or RubyScript2Exe unpack isn't an option (this is supposed to be the harness for a testing system). Has anyone successfully used Crate to package up something on Windows? If so, what was your build environment like and can you pass on any other hints?
I've tried and worked in getting Crate work under Windows, but is a more complicated system than I would expect.
If extraction of code for your system is your problem. I recommend take a look to Exerb, and specially: exerb-mingw hosted on GitHub exerb-mingw
It will generate a single executable like Ocra or RubyScript2Exe, but with the difference that the source code will not be extracted and extensions will be dynamically loaded.
This works perfectly with RubyInstaller packages, and is being used with Pik (Ruby version manager for Windows).
Hope this helps.
You can embed a Ruby interpreter and script into a C program, which may be easier than trying to run Crate. Here are some helpful links that describe how to do this, and may provide enough sample code to use as a skeleton for what you are trying to build.