Hello everybody!
I am learning Pyhton and I’d like to use pyRoot but I have a problem: pyRoot works with Python2 but not with Python3.
When I use Python2 I get:
alessandro@alessandro-X550CC:~/Scrivania$ python
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>
Everything is fine! However, when I use Python3 I get:
alessandro@alessandro-X550CC:~/Scrivania$ python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alessandro/Scrivania/root/lib/ROOT.py", line 24, in <module>
import cppyy
File "/home/alessandro/Scrivania/root/lib/cppyy.py", line 61, in <module>
import libPyROOT as _backend
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)
>>>
What’s the problem, please?
Thanks in advance to everybody!
The issue is that you are using a ROOT installation that was built for Python2. Therefore, it works when you use the Python2 interpreter, but throws an error when you use Python3. Current PyROOT can only be built for one Python version, we have removed that limitation in a new PyROOT we are working on but it is still present in the current one.
If you want to use Python3, you will need to build ROOT with Python3, by specifying the right parameters of CMake:
-- Looking for python
-- Found PythonInterp: /usr/bin/python3 (found version "3.6.9")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found version "2.7.17")
CMake Error at cmake/modules/SearchInstalledSoftware.cmake:444 (message):
Version mismatch between Python interpreter (3.6.9) and libraries (2.7.17).
ROOT cannot work with this configuration. Please specify only
PYTHON_EXECUTABLE to CMake with an absolute path to ensure matching
versions are found.
Call Stack (most recent call first):
CMakeLists.txt:159 (include)
I have also tried with the following line of CMake:
The error you see usually means that you don’t have development libraries/headers for the version of Python that you are trying to build against. Please make sure that headers for Python3 are available in PYTHON_INCLUDE_DIR. I also recommend to only set PYTHON_EXECUTABLE, as CMake can detect the rest by itself. Cheers,