Not being able to import matplotlib into my code

Hello, I am having issues importing matplotlib into my code after specifying the python path within my .bash_profile (mac) compatible with ROOT. By trying to import matplotlib I get the following error:

ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import)

I have tried specifying another possible python path in the .bash_profile by calling

PYTHONPATH="/Users/opt/anaconda3/lib/python3.9:$PYTHONPATH"
export PYTHONPATH

but the same error still persists.
My .bash_profile file currently looks as follows:

export ROOTSYS=/usr/local/Cellar/root/6.26.06_1
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ROOTSYS/lib

export LD_LIBRARY_PATH=/Users/Documents/framework/MG5_aMC_v3_4_1/delphes-master:$LD_LIBRARY_PATH
export ROOT_INCLUDE_PATH=/Users/Documents/framework/MG5_aMC_v3_4_1/delphes-master/external/
export ROOT_INCLUDE_PATH=/Users/Documents/framework/MG5_aMC_v3_4_1/delphes-master/classes/:$ROOT_INCLUDE_PATH

. $(brew --prefix)/bin/thisroot.sh


# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

alias python='/usr/local/bin/python3'
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/3.10/bin

Does anyone know what could be done so that I can use both ROOT and matplotlib simultaneously?
Many thanks in advance.

This is the ROOT forum, not the mpl forum. But maybe you’re lucky and one of our users can help.

You seem to mix different python versions (β€œ.../anaconda3/lib/python3.9”, β€œ.../Python.framework/Versions/3.10”, β€œ/usr/local/bin/python3”).
This will not work.
Make sure that you use the same python version that your ROOT was built for (β€œroot-config --python-version”).

1 Like

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