You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
std::runtime_error when loading matplotlib.pyplot #8
On osx 10.10.5, the examples build cleanly but when I try to run them I get:
.libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Error loading module matplotlib.pyplot!
/bAbort trap: 6
I suspect this is a system path issue as I have matplotlib installed on the system:
In [9]: matplotlib.path
Out[9]: ['/Library/Python/2.7/site-packages/matplotlib']
Hi, I don't know much about mac, but
a) Does it work if you try to 'import matplotlib.pyplot' from the python interpreter?
b) If yes, does it work if you add PYTHONPATH=/Library/Python/2.7/site-packages to the environment?
With PYTHONPATH set, then I get the error about not being able to import matplotlib.pyplot.
terminate called after throwing an instance of 'std::runtime_error'
what(): Error loading module matplotlib.pyplot!
It's also worth saying that I am building this with bazel, so it's possible that is causing problems. But I don't think it's related to what I'm seeing.
On my system (macos on an M1 Mac, installed python using homebrew), it turned out that I got this error because matplotlib was installed only for Python 3.10, while matplotlib-cpp was using Python 3.11.
Installing matplotlib for that specific Python version helped: python3.11 -m pip install matplotlib
__
p.s. After this, I ran into some other runtime issus. I'm trying to get the examples running.
After undoing what was previously suggested here, I got most (not all!) examples working!
-> Had to remove backend: TkAgg from ~/.matplotlib/matplotlibrc
I am same issue now,use Anaconda on Ubuntu 22.04, Python version is 2.7,
I installed in a virtualenv. run by vscode, I write tasks.json,becuse I want to debug by vscode GUI
"-I", "/home/agatha/.conda/envs/myenv/include/python2.7",
"-L", "/home/agatha/.conda/envs/myenv/bin",
"-L", "/home/agatha/.conda/envs/myenv/lib/python2.7/site-packages",
"-lpython2.7",
And than I terminal input "conda activate myenv"
oh sad occur runtime_error("Error loading module matplotlib!");
Activity
lava commentedon Jun 10, 2016
Hi, I don't know much about mac, but
a) Does it work if you try to 'import matplotlib.pyplot' from the python interpreter?
b) If yes, does it work if you add PYTHONPATH=/Library/Python/2.7/site-packages to the environment?
alvas commentedon Jan 2, 2017
I get the same error on Mac.
a) I can import matplotlib.pyplot from python interpreter correctly.
b) after I set PYTHONPATH environment variable, I still get the same error.
NTT123 commentedon Oct 16, 2017
I found a solution at https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python?noredirect=1&lq=1
kgreenek commentedon May 31, 2020
I am running into this same issue now, although in a different environment.
I'm running on Ubuntu 18.04. Python version is 3.7. Pip dependencies (i.e. matplotlib) are installed in a virtualenv.
In order for it to be able to import matplotlib, I have to explicitly set my PYTHONPATH like below, even though I have activated the virtualenv:
With PYTHONPATH set, then I get the error about not being able to import matplotlib.pyplot.
It's also worth saying that I am building this with bazel, so it's possible that is causing problems. But I don't think it's related to what I'm seeing.
Friduric commentedon Nov 15, 2021
Same error on Windows 10, Visual Studio 2019, Python 310
goldbattle commentedon Dec 8, 2021
I had this error in an ubuntu docker 16.04 and 20.04 container.
I solved it by first trying to import it as suggested:
From there I got this error:
Which once I installed tk everything worked correctly.
It is a very misleading error IMO.
https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter
Sidelobe commentedon Jun 7, 2023
On my system (macos on an M1 Mac, installed python using homebrew), it turned out that I got this error because
matplotlibwas installed only for Python 3.10, whilematplotlib-cppwas using Python 3.11.Installing
matplotlibfor that specific Python version helped:python3.11 -m pip install matplotlib__
p.s. After this, I ran into some other runtime issus. I'm trying to get the examples running.
After undoing what was previously suggested here, I got most (not all!) examples working!
-> Had to remove
backend: TkAggfrom~/.matplotlib/matplotlibrcAgathaZhang commentedon Sep 2, 2024
I am same issue now,use Anaconda on Ubuntu 22.04, Python version is 2.7,
I installed in a virtualenv. run by vscode, I write tasks.json,becuse I want to debug by vscode GUI
"-I", "/home/agatha/.conda/envs/myenv/include/python2.7",
"-L", "/home/agatha/.conda/envs/myenv/bin",
"-L", "/home/agatha/.conda/envs/myenv/lib/python2.7/site-packages",
"-lpython2.7",
And than I terminal input "conda activate myenv"
oh sad occur runtime_error("Error loading module matplotlib!");
onnipohjavirta commentedon Oct 2, 2024
In my case, this seemed to be fixed by installing python-tk
apt install python-tk