0
votes

I'm having trouble importing a python module using rubypython. I know that the library paths are different which I think is the issue. For example running:

require "rubypython"
require 'pry'

RubyPython.start # start the Python interpreter

py = RubyPython

sys = py.import 'sys'
p sys.version
p sys.path.inspect

RubyPython.stop # stop the Python interpreter

gives:

'2.7.2 (default, Oct 11 2012, 20:14:37) \n[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]'
"['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-darwin', '/usr/lib/python2.7/plat-mac', '/usr/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/Extras/lib/python', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload']"

but in python itself the paths are different:

import sys

sys.path ['/Users/brendan/.starcluster/plugins', '', '/Library/Python/2.7/site-packages/StarCluster-0.9999-py2.7.egg', '/Library/Python/2.7/site-packages/workerpool-0.9.2-py2.7.egg', '/Library/Python/2.7/site-packages/ssh-1.7.14-py2.7.egg', '/Library/Python/2.7/site-packages/pycrypto-2.6-py2.7-macosx-10.8-intel.egg', '/Library/Python/2.7/site-packages/optcomplete-1.2_devel-py2.7.egg', '/Library/Python/2.7/site-packages/iptools-0.6.1-py2.7.egg', '/Library/Python/2.7/site-packages/pyasn1-0.1.7-py2.7.egg', '/Library/Python/2.7/site-packages/decorator-3.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/Jinja2-2.7.1-py2.7.egg', '/Library/Python/2.7/site-packages/boto-2.12.0-py2.7.egg', '/Library/Python/2.7/site-packages/paramiko-1.11.0-py2.7.egg', '/Library/Python/2.7/site-packages/MarkupSafe-0.18-py2.7-macosx-10.8-intel.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']

Anyone know how to make RubyPython use the same paths as if I ran the python interpreter (I'm very new to python by the way, so this might be a simple python thing not related to ruby at all).

1

1 Answers

0
votes

In Python you would do

 sys.path.extend(['/Users/brendan/.starcluster/plugins', '', '/Library/Python/2.7/site-packages/StarCluster-0.9999-py2.7.egg', '/Library/Python/2.7/site-packages/workerpool-0.9.2-py2.7.egg', '/Library/Python/2.7/site-packages/ssh-1.7.14-py2.7.egg', '/Library/Python/2.7/site-packages/pycrypto-2.6-py2.7-macosx-10.8-intel.egg', '/Library/Python/2.7/site-packages/optcomplete-1.2_devel-py2.7.egg', '/Library/Python/2.7/site-packages/iptools-0.6.1-py2.7.egg', '/Library/Python/2.7/site-packages/pyasn1-0.1.7-py2.7.egg', '/Library/Python/2.7/site-packages/decorator-3.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/Jinja2-2.7.1-py2.7.egg', '/Library/Python/2.7/site-packages/boto-2.12.0-py2.7.egg', '/Library/Python/2.7/site-packages/paramiko-1.11.0-py2.7.egg', '/Library/Python/2.7/site-packages/MarkupSafe-0.18-py2.7-macosx-10.8-intel.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'])

to add all the paths. I do not know what you do in Rubypython maybe sys.path << [...?