0

Including the line import matplotlib.pyplot as plt in any file makes any python program exit immediately without any error message. Trying to import it in the python shell forces the shell to exit.

I know this actually happened to me not long ago and the issue was a faulty matplotlib installation. I'm on Windows and I'm using the miniconda/anaconda3 distribution. I'm on a virtualenv I made called py_summer. I tried running both conda uninstall matplotlib then conda install -c conda-forge matplotlib from the anaconda website with the virtualenv active. This didn't change anything. I still assume a possibly corrupted installation, I just don't know what else I can do at this point.

Edit: If I deactivate the virtualenv, the matplotlib instruction works...

I don't want to discard the entire py_summer env I have but I already tried uninstalling matplotlib then reinstalling it... What could I do? Should I maybe just uninstall matplotlib on my whole machine outside of the env?

Byron Smith
  • 587
  • 10
  • 32
  • One benefit of virtual environments is actually that you can easily remove them and create a new one in no time. So that might be an easy try. Else, I would first try to see if this is a backend problem. Is `import matplotlib` working correctly? Can you see what `matplotlib.rcParams["backend"]` prints? Would changing it to something else help, e.g. `matplotlib.rcParams["backend"] ="TkAgg"`, then `import matplotlib.pyplot`. – ImportanceOfBeingErnest Mar 10 '19 at 22:09
  • import matplotlib works correctly. – Byron Smith Mar 10 '19 at 22:11
  • accidentally posted that comment. But all of your suggestions worked. print(matplotlib.rcParams["backend"]) gave "Qt5Agg." Changing the string here to "TkAgg" made the import instruction work. What is a backend problem with matplotlib, like what does that imply? – Byron Smith Mar 10 '19 at 22:13
  • See [backends](https://matplotlib.org/tutorials/introductory/usage.html#backends). If `matplotlib.rcParams["backend"] ="TkAgg"` followed by `import matplotlib.pyplot` does not crash, it would mean that you have a problem with your Qt installation. You can try reinstalling `pyqt` and see if that changes anything, else there might be a version incompatibility - for further help with that the versions of python, pyqt, matplotlib and possibly other dependencies would be needed to find out more. – ImportanceOfBeingErnest Mar 10 '19 at 22:17
  • I just did a conda remove pyqt and then installed it using `conda install -c anaconda pyqt`. The problem still remains unfortunately. I have `Python 3.5.5 |Anaconda custom (64-bit)`, `pyqt 5.6.0`, `matplotlib 2.2.3`... ` – Byron Smith Mar 10 '19 at 22:54
  • also matplotlib.rcParams["backend"] is still printing "Qt5Agg" – Byron Smith Mar 10 '19 at 22:54
  • and I found this question, seems like it could be a resolution? I'll try to implement it... https://stackoverflow.com/questions/3285193/how-to-switch-backends-in-matplotlib-python – Byron Smith Mar 10 '19 at 22:56
  • [This answer](https://stackoverflow.com/a/3285910/4124317) to that question is what I suggested above, right? So of course if you're happy with using TkAgg from now on, that's totally possible. Concerning the qt backend, does some [minimal pyqt5 program](http://zetcode.com/gui/pyqt5/firstprograms/) (without use of matplotlib) run for you? – ImportanceOfBeingErnest Mar 10 '19 at 22:58
  • Trying to include that import statement of `from PyQt5.QtWidgets import QApplication, QWidget` did not work, it made my python shell exit immediately. So yeah you must be right that there's an issue with pyqt. But conda remove pyqt didn't address the problem and I don't have a pip version of pyqt. – Byron Smith Mar 10 '19 at 23:17
  • 1
    Ok, so this is then really completely independent of matplotlib. I think what you can do is to ask a new question about `from PyQt5.QtWidgets import QApplication, QWidget` not working correctly (use the with the respective tags). In order for someone to suggest a possible solution, you would probably need to dump the exact versions in use (`conda list`). – ImportanceOfBeingErnest Mar 10 '19 at 23:30

0 Answers0