PyROOT and Anaconda


I’ve got ROOT and Python3 installed and I want to use pyRoot. Unfortunately, when I try to import ROOT it gives me an error message:

ImportError: dynamic module does not define module export function (PyInit_libPyROOT)

I am using python through the anaconda distribution and as I have read there seems to be a compiler issue or something that seems to cause trouble.

I have also read soemthing about conda forge and tried installing ROOT via

conda install -c conda-forge root

Since I am kind of a newbie I don’t know what this does or how it should solve the problem. It didn’t for me.
Would appreciate some help.

@etejedor Can you help?

how did you install ROOT exactly? Can you remove all ROOT installations from your system, including from the base conda environment (conda uninstall root should suffice), then try the steps described here?

Hope this helps!

Just to add on what @eguiraud already said, the error you reported happens because you are trying to use ROOT from Python3 but it was build for Python2.

Initially I installed ROOT by building it from the source file.

@eguiraud Now I tried installing root through

conda install root root-binaries root-dependencies root_base

as suggested. It said that it would add root, root-binaries… to my anaconda environment and downloaded and installed a bunch of packages. The process was successful.

But I still get the same error message when trying to run my scripts.

Did you conda activate the environment before installing ROOT? I.e. are you sure that you are using the conda installation and not the same broken installation of your first post? For example, what does which root say?


No, I did not know about conda activate.
But which root gives me:


I assume that is a good sign?

UPDATE: It is now working. Thank you.

@eguiraud Hi, maybe you could help me one more time.

I can’t run scripts which contain pyroot commands from my shell. I always get the error message

Traceback (most recent call last):
  File "", line 15, in <module>
    import ROOT
  File "/Applications/root_v5.34.38/lib/", line 103, in <module>
    import libPyROOT as _root
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)

root 5.34 is an old Version I got installed. I don’t know what this implies. When I run

which root

I get


So to my understanding this should be fine.

When I build my scripts within my Text editor Sublime with a configured conda build system everything works just finde. I don’t get it.

Hi @Jailbone,
uhm looks like python is looking up the 5.34 installation first when searching for the ROOT module to import. Probably the 5.34 installation is setting some environment variables such as PYTHONPATH?

Make sure that which python also points to the anaconda3 python installation and that PYTHONPATH, PATH, LD_LIBRARY_PATH do not mention the 5.34 installation.


Hi thanks I made it work :wink:

1 Like

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