0

我正在尝试设置 PyROOT 以在 Mac OS X Yosemite 上使用 Pycharm 4。

我已经安装了 ROOT(本地),启用了 python 选项,并设置了所有必要的环境路径。

echo $PYTHONPATH
/Users/natalia/Software/root/lib:/Users/natalia/Software/root/bin:/Users/natalia/Software/root

它在 shell 解释器中工作得很好:

python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.__file__
'/Users/natalia/Software/root/lib/ROOT.pyc'
>>>

在 Pycharm 中,我尝试使用 Preferences->Project Interpreter->More->Show paths 将这些路径添加到解释器...

显示的路径如下:

file:///Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg
file:///Users/natalia/Software/root/lib
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
file:///System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
file:///System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
file:///Library/Python/2.7/site-packages
file:///Users/natalia/Software/root/bin
file:///Users/natalia/Software/root

我在 Pycharm 中创建了以下文件:

import os
os.system("echo $PYTHONPATH")
import ROOT

运行时,它返回:

Traceback (most recent call last):
/Users/natalia/Software:/Users/natalia/Software/root:/Users/natalia/Work/Projects/untitled
 File "/Users/natalia/Work/Projects/untitled/l.py", line 3, in <module>
    import ROOT
ImportError: No module named ROOT

请注意,在 Pycharm 中从 python 打印的这个 PYTHONPATH 不包括(由于我不知道的原因)实际包含 ROOT.pyc 文件的路径,即:'/Users/natalia/Software/root/lib'

我也试过做肮脏的把戏

os.system("export PYTHONPATH=$PYTHONPATH:/Users/natalia/Software/root/lib") 

但我发现如果我之后打印它实际​​上并没有改变路径。

我对 Pycharm 从哪里获得路径感到非常困惑。任何可能的解决方案都将受到欢迎并不胜感激。

4

1 回答 1

3

你可能已经想通了,但以防万一……

import sys
sys.path.append('/Applications/Misc/root/lib')
import ROOT
print ROOT.TTimeStamp().AsString()

将该搜索路径添加到 Python(以及扩展名为 PyCharm);该片段在 PyCharm 中为我提供了以下输出:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/Users/rrios/PycharmProjects/untitled/dummy.py
Thu, 02 Jul 2015 01:07:57 UTC +628998000 nsec

Process finished with exit code 0
于 2015-07-02T01:12:32.783 回答