K.Mulier
K.Mulier

Reputation: 9620

Need tkinter on my python 3.6 installation (Windows 10)

I'm running Python 3.6 on a Windows 10 machine. I want to display a simple matplotlib plot like this:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

Unfortunately, I get the error:

ModuleNotFoundError: No module named 'tkinter'

I try installing tkinter through my terminal:

> pip install tkinter
Collecting tkinter
  Could not find a version that satisfies the requirement tkinter (from versions: )
  No matching distribution found for tkinter

I also tried pip install python3-tk but without success. I found a couple of posts on StackOverflow explaining how to install tkinter properly, but they're all about Python 2 and/or Linux systems. I couldn't find a post particularly for Python 3.6 on Windows 10.

Upvotes: 4

Views: 15174

Answers (3)

Mizat
Mizat

Reputation: 11

OK that is weird it worked like that, I had to re-install before and actually downgrade for it to work and uninstall on windows and have issues on linux also. I've done pip for both and everything else. Windows got it working from downgrading from 3.7 to 3.6 and uninstalling 3.7. So that may help someone.

Also a key factor is having access or a clear 'path' to C:\User\"UserName"\appdata from there usually \local but can be \roaming and it ccan appear in a file that is just named python with the version number after or \Local\packages\PythonSoftwareFoundation.python.3.7 or many other files it has shown up in, due to what seems random half the time I read about these occurances and even on Pythons help page, they suggest all the places without giving reason for why it would be in each, seeming like it is almost random.

Upvotes: 0

markroxor
markroxor

Reputation: 6476

Not sure about windows but in Ubuntu you could do sudo apt-get install python3-tk

For windows you can try import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt

if you dont want to use tkinter at all. (Tested in Ubuntu)

Also dont forget to use %matplotlib inline at the top of your notebook if using one.

Upvotes: 1

K.Mulier
K.Mulier

Reputation: 9620

I got it working now. I removed my Python 3.6.1 installation and installed Python 3.6.3 from here:

https://www.python.org/downloads/release/python-363/

I selected the Windows x86-64 executable installer for my Windows 10 computer. While installing, I chose for "custom installation" so I can check which modules I want or don't want. Apparently, tkinter is present by default. Perhaps I had unchecked it on my last installation (a couple of months ago)?

Anyway, I got things working now. But it seems still a bit odd to me that I had to do a complete reinstallation for this to work. A simple pip install tkinter should also do the job (in my opinion).

Upvotes: 2

Related Questions