Why does it say that no module named tkinter?

后端 未结 2 1398
迷失自我
迷失自我 2020-12-12 06:40

Good day. I installed pyhton 2 and python 3 in my laptop. And i\'m using python 3 interpreter in writing my codes. Here is my code.

#! /usr/bin/python3

from         


        
2条回答
  •  醉梦人生
    2020-12-12 06:57

    python 2 and python 3 use tkinter in a different way.

    Note: Tkinter has been renamed to tkinter in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

    The above lines are from python documentation. Not sure if python is loading tkinter using python 2 or python 3..May be internal PYTHONPATH is messed up Rather try this,

    try:
      import tkinter as tk
    except ImportError:
      import Tkinter as tk
    

    Note: In these situations where you use multiple versions of same modules, try using virualenv

    Virtual Env

提交回复
热议问题