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" Commented 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 Commented Aug 31, 2017 at 10:53
  • It's tkinter, not tkiter Commented 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 Commented Aug 31, 2017 at 10:57
  • I am using anaconda distro, and it run well without above issue :) Commented 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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

Try switching the backend from tkinter to agg using -

matplotlib.use('agg')

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.