关于ruby:rubypython和python中的不同加载路径

Different loadpaths in rubypython and python

我在使用rubypython导入python模块时遇到问题。 我知道库路径是不同的,我认为是问题。 例如运行:

1
2
3
4
5
6
7
8
9
10
11
12
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

得到:

1
2
3
'2.7.2 (default, Oct 11 2012, 20:14:37)
[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']"

但在python本身,路径是不同的:

导入系统

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']


任何人都知道如何使RubyPython使用相同的路径,就好像我运行python解释器一样(顺便说一下,我对python很新,所以这可能是一个简单的python,根本不涉及ruby)。


在Python中你会这样做

1
 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'])

添加所有路径。 我不知道你在Rubypython做什么sys.path << [...