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.
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
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.
Try switching the backend from tkinter to agg using -
matplotlib.use('agg')
Related
Running python3 to bring me into python, and then simply running import tkinter results in the following error:
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
However when going into the python shell (not python3), import tkinter works fine as expected. How can I get tkinter to work with Python3?
Please note the following:
I am on MacOS Catalina
I am working with Python 3.7.3 (based off python3 --version)
It looks like my python3 executable is (/usr/bin/python3)
The path for tkinter is /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/
I am able to run idle in Terminal, but I can't run idle3
I don't think I am using a virtualenv or pyenv or anything like that
You need a separate Tcl/Tk installation. Try a newer version of the Python3 binary installer from python.org, which bundles Tcl/Tk.
Don't install tkinter through idle. Try idle3. If nothing, install python3-tk using your OS installer. (I have apt. I'm on Debian.). Good luck!
Don't use _ in import _tkinter
Use import tkinter
I am Sure that this will work. If it works then tick my answer.
Fist open Command Prompt and run pip install tkinter
Then open your python project and press Ctrl + S.
Then run your project.
I hope my answer is useful to you.
I just downloaded Pycharm because Spyder on Anaconda wasn't working anymore on my Mac. I am trying use Tkinter and have tried to run code using both
from tkinter import *
and
import tkinter as tk
The second is from my python class. Both times it returns
ImportError: No module named tkinter
I have tried to search for "tkinter" on Python Interpreter but there's no solid "tkinter." Only others like tkinter.math. Please help.
Tkinter would not be visible on Python Interpreter since it is a part of standard Python installation, the only additional modules or packages which user downloads are visible in Settings. Since, Spyder on your PC is not working as well, make sure python is installed properly and is configured correctly with path details properly set up.
I think you should check the interpreter of PyCharm.
Or Reinstall the python package and make a virtual environment.
hey i'am new in programming ..
I am doing a mini project in python in pycharm..
I am getting an error which says Tkinter module not installed..
plzz anybody can help..!!
in case of Python3.6, tkinter is a part of the standard library available from when you install your python. However if you want to know if tkinter is installed just import it in the python console
import tkinter
if you didn't see any errors you are good to go.
In Window, I installed python3.6
and, installed matplotlib by commandline:
pip install matplotlib
After installation, I was running matplotlib in python console,
import matplotlib.pyplot as plt
import matplotlib.pylab as plb
In python36\lib\site-packages
I want in blender to use the matplotlib library in python,
Can I copy the matplotlib in python36\lib\site-packages of Python into the Blender\2.78 \python\lib\site-packages?
I tried copying but only importing matplotlib, but when `import matplotlib.pylot as plt the error is as follows
I do not know how to fix it, please help me
Thank you so much!
First you will want to make sure you use the same python version as blender was built with, for blender 2.78 that is python 3.5. For compiled python modules like matplotlib this is more important than pure python modules.
There are few ways to use third party modules, first like you are trying, is to install them into blender's copy of python. Another way is to delete blender's python so that it uses the system installed version. You can also adjust sys.path to allow blender's python to find third party modules.
I am trying to install Basemap, and beforehand I already have the prerequisite versions of Matplotlib, Python and Numpy working on my Mac. To install Basemap I am following the instructions in this website http://matplotlib.org/basemap/users/installing.html
I seemed to progress quite well with the steps, until the very end which is "Check your installation by running from mpl_toolkits.basemap import Basemap at the python prompt." I got "ImportError: cannot import name pyproj" from a line that reads "---> 30 from mpl_toolkits.basemap import pyproj".
Does anyone have any idea? Many thanks!
The compiled module could be accessible by python. To achieve that you should put the module into python path or you need to add the location of the module to PYTHONPATH environment variable.
To see the python installations paths you can write these lines to python shell:
import sys
for path in sys.path:
print(path)
The code will show the paths python is looking for modules.
After you compile the c library, you need to go to upper folder and run python setup.py install as it's said in the installation page. This will put python modules into one of your python paths.
I had the same problem installing basemap-1.0.7.
I found that the file
/usr/lib64/python2.6/site-packages/mpl_toolkits/basemap/init.py
had a reference to axes-grid1, but python lists only module axes_grid.
So I changed grid1 to grid and now basemap imports without error.
Had the same issue on OSX, found after much faffing that Basemap worked fine with a non-native version of python (for me 2.7.12 with everything under /opt/local/Library/Frameworks...) but not with the native version (for me 2.7.10 with most stuff under /System/Library/Frameworks... and Basemap under /Library/...). I did note also that under the native version there was already some mpl_tooklit content and without the permission to add Basemap there you end up with mpl_toolkit contents in multiple places. I wasn't sure if this was the problem specifically but as I said having it all under opt using non-native python was what solved this for me.