我在使用rubypython导入python模块时遇到问题。我知道库路径是不同的,我认为是问题。例如跑步:
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
给出:
'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']"
但在python本身路径不同:
导入sys
sys.path中 ['/Users/brendan/.starcluster/plugins','','/ Library /Python / 2.7 / site-package / StarCluster-0.9999-py2.7.egg','/ Library /Python / 2.7 / site -packages /workerpool-0.9.2-py2.7.egg','/ Library /Python / 2.7 / site-package / sss-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-package / 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-package / 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-package / paramiko-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 / Version / 1.7 / lib / python27.zip','/ System / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7','/ System / Library / Framew orks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-darwin','/ System / Library / Frame /Python.framework / Version / 7.7 / lib / python2.7 / plat-mac','/ System / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac / lib-scriptpackages','/ System / Library / Frame /Python.framework / Version / 7.7 / Extras / lib / python ','/ System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk','/ System / Library / Frame /Python.framework / Version / 2.7 / lib / python2.7 / lib-old','/ System / Library / Frame /Python.framework / Version / 1.7 / lib / python2.7 / lib-dénd'','/ System / Library / Frame /Python.framework / Version / 2.7 / Extra / lib / python / PyObjC','/ Library /Python / 2.7 / site -packages']
任何人都知道如何使RubyPython使用相同的路径,就像我运行python解释器一样(顺便说一下,我对python很新,所以这可能是一个简单的python,根本不涉及ruby)。
答案 0 :(得分:0)
在Python中你会做
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 << [...
?