Importing root in python

Hi experts

I installed Root 6.10/08 using homebrew. My aim is to import Root in python.
However, I think since the Python version that homebrew installed for me (as a dependency for root) is different than the system python that already exists , I’m having trouble importing root in python.

When I simply type python --version in the terminal I get this:

Python 2.7.10

And, when i check for the homebrew Python by using the “brew info python” command, I get this:

python: stable 2.7.14 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/2.7.14 (3,517 files, 48.4MB) *
  Poured from bottle on 2017-10-19 at 12:27:35
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: sphinx-doc ✘, pkg-config ✔
Required: openssl ✔
Recommended: readline ✔, sqlite ✔, gdbm ✔
Optional: sphinx-doc ✘, tcl-tk ✘, berkeley-db@4 ✘
==> Options
--with-berkeley-db@4
	Build with berkeley-db@4 support
--with-poll
	Enable select.poll, which is not fully implemented on macOS (https://bugs.python.org/issue5154)
--with-quicktest
	Run `make quicktest` after the build (for devs; may fail)
--with-sphinx-doc
	Build HTML documentation
--with-tcl-tk
	Use Homebrew's Tk instead of macOS Tk (has optional Cocoa and threads support)
--without-gdbm
	Build without gdbm support
--without-readline
	Build without readline support
--without-sqlite
	Build without sqlite support
--HEAD
	Install HEAD version
==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
  export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Pip and setuptools have been installed. To update them
  pip2 install --upgrade pip setuptools

You can install Python packages with
  pip2 install <package>

They will install into the site-package directory
  /usr/local/lib/python2.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python.html

So clearly the two pythons are different

When I open the system python by simply typing python and then then try to import root by typing import ROOT, i get this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ROOT

How do i import homebrew root from system python a.k.a Python 2.7.10 ?

Please make sure to add the library directory where libPyROOT.so was installed to the PYTHONPATH environment variable. You will also need to make sure that the python executable used by ROOT during the build was the correct one (things will be broken if you build with python 2.x and then try to import the modules from python 3.x).

Sorry, just realized you installed via homebrew (I’m reading on my phone). In that case, you probably need to use python also from homebrew, although it may work with your system Python if you export the proper PYTHONPATH, since it’s also 2.x.

Take a look at these recent topics. This issue has been discussed quite frequently on the forum lately. There are also other topics that can be found using the search that should help you.


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