1

I am trying to write a blender script for which I need matplotlib.pyplot. When trying to import matplotlib.pyplot as plt I get the following error:

ImportError: No module named 'tkinter'

However, using the installed anaconda version, the import is no problem. The common solution to run

sudo apt-get install python3-tk

does not solve the problem. I tried to add the Path to tkinter with:

sys.path.append('/usr/lib/python3.4/tkinter/')

sys.path.append('/home/<username>/anaconda3/lib/python3.6/tkinter/')

Both commands did not resolve the error.

8
  • Did you try to install tkinter using pip: "pip install tkinter"
    – Tin Luu
    Aug 31, 2017 at 10:51
  • I was not aware that this is possible. Using tkinter or python3-tk both result in Could not find a version that satisfies the requirement tkinter (from versions: ) No matching distribution found for tkinter
    – McLawrence
    Aug 31, 2017 at 10:53
  • It's tkinter, not tkiter
    – Tin Luu
    Aug 31, 2017 at 10:56
  • Sorry. Just a typo. But same error message from pip. I read that, since it is a C++ package, it cannot be installed via pip
    – McLawrence
    Aug 31, 2017 at 10:57
  • I am using anaconda distro, and it run well without above issue :)
    – Tin Luu
    Aug 31, 2017 at 11:04

3 Answers 3

1

I managed to import tkinter (and use it with matplotlib.pyplot) from Blender as I explained here:

https://stackoverflow.com/a/56050748/4511978

Hope it helps!
Andres

0

On Linux, you shouldn’t need to mess around with pip to install tkinter, since it’s a standard Python module. Also the Blender package should use the system Python, so it will have access to all system Python modules.

But ... tkinter is a GUI framework, and trying to use this will conflict with Blender’s own GUI.

Another option might be to use Matplotlib in offscreen-plotting mode, which doesn’t need a GUI.

0

Try switching the backend from tkinter to agg using -

matplotlib.use('agg')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.