importError tkinter when importing matplotlib - python

I am unable to import matplotlib on this deep learning AMI from aws marketplace
import matplotlib.pyplot as plt
And I get this error
ImportError: No module named 'tkinter'
What I've tried (and the errors returned):
pip install tkinter
> No matching distribution found for TKinter
sudo yum install tkinter
> No package tkinter available.
> Error: Nothing to do

I personnally had this kind of troubles with tkinter, before to realize it requires a 't' in python3 and a 'T' in python2. so when I need compatibility my codes contain:
import sys
if sys.version_info[0]>2:
# for Python 3
import tkinter as tk
else:
# for Python 2
import Tkinter as tk
I hope this help

First find location of matplotlibrc file
import matplotlib
matplotlib.matplotlib_fname()
u'/usr/local/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
Then go to this file and change the current configuration of backend to
backend : agg
This does not solve the problem of import Tkinter, but it does allow the import of pyplot

This worked for me:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
Had the same problem after updating to new matplotlib 2.x on python 3.5.x

Related

Python msilib for mac

I'm trying to run a python script that has the following import statement:
from ast import keyword
from email.policy import default
from msilib.schema import ComboBox
from statistics import variance
import tkinter as tk
from tkinter import Variable, ttk
from turtle import onclick, width
I get an error on From msilib.schema import Combobox. I'm using a Mac and I see the lib is Microsofts, is there a way I can import a package so that I can use msilib on my Machine.
EDIT: The work around for anyone having the same issue is to run a virtual box with windows. It would still be nice to know how to run it on MAC but oh well...

transform python tkinter GUI to EXE file

I have been working on developing a GUI application using tkinter which is 100% working properly when running it from pycharm... and now I can't convert my script into an EXE file.
I have tried pyinstaller, cxfreeze and py2exe but everyone of them has a problem. pyinstaller show me 'Fatal error'... and cxfreeze seems to have a problem with MATPLOTLIB
Here are the libraries I am using:
import numpy as np
import tkinter
from random import randint
from tkinter import *
import tkinter as tk
from math import sqrt
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from math import sqrt
from scipy import stats
from scipy.stats import beta
I don't want to post my code due to confidientality issues...
Does anybody has another idea ot do this ?
EDIT:
I reinstalled python as admin and reinstalled pyintaller
enter image description here
and when I tried to convert the script here is the command error it shows:
'pyinstaller' is not recongnized as an internal command or external ...
also I need to mention that the exe file of pyintaller in not founded in the directory of installation of python in C:programfiles/python37

Cannot run my .exe python program using cx_freeze

I wrote a program where I imported those lib :
from math import*
from pylab import*
import numpy as np
import matplotlib
import matplotlib.backends.backend_tkagg
import numpy as np
import matplotlib.pyplot as plt
and I wanted to make an executable out of it (the .py already runs using pylab) so in the Windows terminal (in the Python's script folder) I did the command cxfreeze solver.py : this creates a solver.exe in Dist folder.
When I tried to run this executable, there is :
File "C:\Users\*****\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: Le module spécifié est introuvable.
In english : the specified module is not found
I read several help on the site and on internet but it nerver fixed it, and after few days of searching I begin to give up. Please help !

Matplotlib backend GTK3 Agg using Cairo?

I don't understand why while I' trying to use the Gtk3Agg backend and I end up with an error telling me the cairo module is not found.
** (simple_plot_in_gtk3.py:312517): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
Traceback (most recent call last):
File "simple_plot_in_gtk3.py", line 5, in
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
File "/Produits/publics/x86_64.Linux.RH6/python/3.4.1/lib/python3.4/site-packages/matplotlib-1.3.1-py3.4-linux-x86_64.egg/matplotlib/backends/backend_gtk3agg.py", line 1, in
import cairo
ImportError: No module named 'cairo'
I'm trying to run the matplotlib/GTK3 example from matplolib site.
Installing Python binging for Python works:
$ pip install pycairo
If you look at the backend_gtk3agg.py file, you'll see that the first lines in the file are;
import cairo
import numpy as np
import sys
import warnings
import backend_agg
import backend_gtk3
from matplotlib.figure import Figure
from matplotlib import transforms
So, yes, the gtk3agg backend requires the cairo library and its Python bindings. And numpy.
It uses Cairo for ImageSurface buffers, because that is something AGG does not provide. I do not know why the gtk3agg developers chose this method. Presumably because it was convenient.

why this a python script works on OSX and not on Windows?

I have a python script which runs perfectly on OSX.
After installing python, numpy and matplotlib on windows I cannot understand why the same does not run on windows.
Do you have any idea?
import numpy
from Tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
# main App class
class App:
def __init__(self, master):
# Create a container
frame = Frame(master)
frame.pack()
root = Tk()
app = App(root)
root.mainloop()
This is the error I get in windows
After installing dateutil I have a new error
I intalled also pyparsing, and now getting the error that I miss the six package, but I don't have any idea how to install that now.
It looks like you need to install dateutil on the windows machine. It used to come bundled with matplotlib but you now need to install it.
Does
import dateutil
throw an error?
There's a list of dependencies here: http://matplotlib.org/users/installing.html which include dateutil, which seems to be working now, and pyparsing which seems to still be missing.

Categories

Resources