I am having trouble with tkinter and python on my Mac, I'm running Leopard.I did a port install of python2.6, numpy, scipy, matplotlib, but when I try and import matplotlib.pyplot, I get the following error. I think there is a conflict with the pre-built version of python that comes with OSX. I get the following error, and I am not sure how to fix it. I have already tried installing tk 8.5, but that has not helped. Below is the error that I am getting, any help would be awesome:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_tkagg.py", line 8, in <module>
import Tkinter as Tk, FileDialog
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/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

Try to import Tkinter by itself to see if the problem is with Tkinter or matplotlib, or TCL & Tk are not installed. What is a "port install". Those packages should come pre-built from the standard Mac repositories. Generally speaking, a problem like this occurs when the library is installed in a different location. There are several possible things to do depending. On Linux we would check the PYTHONPATH to see where Python searches, or print sys.path.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.