Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::runtime_error when loading matplotlib.pyplot #8

Open
kesinger opened this issue Jun 10, 2016 · 9 comments
Open

std::runtime_error when loading matplotlib.pyplot #8

kesinger opened this issue Jun 10, 2016 · 9 comments

Comments

@kesinger
Copy link

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']

@lava
Copy link
Owner

lava commented 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
Copy link

alvas commented 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
Copy link

NTT123 commented Oct 16, 2017

I found a solution at https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python?noredirect=1&lq=1

Create a file ~/.matplotlib/matplotlibrc there and add the following code: backend: TkAgg

@kgreenek
Copy link

kgreenek commented 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:

export PYTHONPATH="/path/to/my/venv/lib/python3.7/site-packages"

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.

@Friduric
Copy link

Same error on Windows 10, Visual Studio 2019, Python 310

@goldbattle
Copy link

goldbattle commented 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:

python3
import matplotlib.pyplot 

From there I got this error:

ModuleNotFoundError: No module named 'Tkinter'

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

sudo apt-get install python-tk # ubuntu 16.04
sudo apt-get install python3-tk # ubuntu 20.04

@Sidelobe
Copy link

Sidelobe commented Jun 7, 2023

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

@AgathaZhang
Copy link

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
Copy link

In my case, this seemed to be fixed by installing python-tk
apt install python-tk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants