Impossible import ROOT from python

Hi,
I am using a Mac 10.13.4
I have a file .ROOT which is export from Geant4.
I have installed root by cmake and python, however, I can not import ROOT from python

In [1]: import ROOT
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-b332e25ada1f> in <module>()
----> 1 import ROOT
ImportError: No module named ROOT

Could anybody please help me?
Thank you in advance.


ROOT Version (e.g. 6.13/03): Built for macosx64
python 2.7.10


Is the directory where you have libPyROOT.so in your PYTHONPATH? If not, your Python won’t be able to find it.

Thank you very much to figure out the problem Amadio,
I am a newbie in bash_profile ( I am using Mac). Could you please help me to link them together.
I have that file here: /Users/hoang/root/build/lib/libPyROOT.so
I have installed my python in: /Users/hoang/Library/Python/2.7/lib/python/site-packages

thank you in advance.
hoang thuong

Please add

export PYTHONPATH=$PYTHONPATH:/Users/hoang/root/build/lib

to your ~/.bash_profile setup. That should do. Cheers,

Thank you again for your help amadio,

this is my .bash_profile:

export PATH=$PATH:/usr/local/bin
#alias sshcc=‘ssh -Y hoang@sshcc1.kek.jp’

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

export PYTHONPATH=$PYTHONPATH:/Users/hoang/root/build/lib

#export PYTHONPATH="$PYTHONPATH:/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7"
#export PYTHONPATH="$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python"
#export PYTHONPATH=$PYTHONPATH:$ROOTSYS/lib


AND This is python places:

print ‘\n’.join(sys.path)

/usr/local/lib/python2.7/site-packages/pyFFTW-0.10.1.dev0+a131a88-py2.7-macosx-10.11-x86_64.egg
/Users/hoang/root/build/lib
/Users/hoang
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Users/hoang/Library/Python/2.7/lib/python/site-packages
/usr/local/lib/python2.7/site-packages
/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg
/Library/Python/2.7/site-packages/setuptools-18.5-py2.7.egg
/Library/Python/2.7/site-packages/distribute-0.6.14-py2.7.egg
/Library/Python/2.7/site-packages
/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info


This still doesn’t work (import ROOT), should I reinstall python 2.7?

Thanks.
Thuong

The place for ROOT should probably come last in your list, otherwise ROOT may try to import modules that will not be found. Please post the errors you get too, otherwise it’s hard to guess what’s happening. Thank you.

1 Like

Thank amadio again,

It works now with the python inside a root TPython::Prompt().
In Ipython or python independently it has error when I try to import ROOT( import cppyy).
Anyway thank you very much, I can work with ROOT file now and I would like to close this topic to move to another topic.

Cheers.
Thuong

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.