Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate a python library into a Ruby on Rails application

I want to know if there is a way to integrate a library written in Python into my Rails application. I have always used gems to implement outside libraries so I have no idea how to do this(yet).

Is it possible to use this Python library?

like image 851
Maximus S Avatar asked Jun 01 '13 00:06

Maximus S


People also ask

Can we use Python in ROR?

The two languages have no similarities allowing one to run code from the other, so there's no way to call a library from one with the other directly.

How do I run a Python script in Rails?

To do so, you would need to make your script into a proper Python module, start the bridge when the Rails app starts, then use RubyPython. import to get a reference to your module into your Ruby code. The examples on the gem's GitHub page are quite simple, and should be sufficient for your purpose.


1 Answers

This is mostly what you want:

Calling Python from Ruby

I've looked into this question before and, excepting the Heroku deploy, the answer was "easily! check this out". (On a fun note, there's a gem to let you embed Perl code in a Ruby file)

However, while I can't seem to find it right now, I remember reading that deploying both to Heroku required a custom buildpac, since one won't normally include the binaries necessary for the other.

like image 128
Narfanator Avatar answered Oct 06 '22 00:10

Narfanator