0

I am having trouble getting my matplotlib library to work. I am running it on a virual environment, and I have installed numpy, and matplotlib. I first open my virtual environment, activate python, then I enter,

import matplotlib 

everything goes fine, but then I enter,

import matplotlib.pyplot as plt

I get the error,

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

I have tried a number of different solutions to no avail. What could be the problem?

ImportanceOfBeingErnest
  • 251,038
  • 37
  • 461
  • 518
Kendall Reid
  • 65
  • 2
  • 6

1 Answers1

0

Use the below mentioned commands:

import matplotlib
matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt

This worked for me. I hope it helps.

sufi
  • 130
  • 3
  • 9