【问题标题】:Pycharm 4 no module named ROOT, when importing a locally installed module (PyROOT), that is working fine from shell on Mac OS X YosemitePycharm 4 没有名为 ROOT 的模块,在导入本地安装的模块 (PyROOT) 时,该模块在 Mac OS X Yosemite 上的 shell 中运行良好
【发布时间】:2015-07-19 12:30:07
【问题描述】:

我正在尝试设置 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 从哪里获取路径感到非常困惑。 任何可能的解决方案都将受到欢迎并不胜感激。

【问题讨论】:

    标签: python macos pycharm osx-yosemite pyroot


    【解决方案1】:

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

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

    将该搜索路径添加到 Python(以及 PyCharm 扩展名); sn-p 在 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
    

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 2019-04-16
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多