matplotlib error - no module named tkinter

后端 未结 16 1665
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 04:10

I tried to use the matplotlib package via Pycharm IDE on windows 10. when I run this code:

from matplotlib import pyplot

I get the followin

16条回答
  •  执念已碎
    2020-11-28 04:21

    For the poor guys like me using python 3.7. You need the python3.7-tk package.

    sudo apt install python3.7-tk

    $ python
    Python 3.7.4 (default, Sep  2 2019, 20:44:09)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    Traceback (most recent call last):
      File "", line 1, in 
    ModuleNotFoundError: No module named 'tkinter'
    >>> exit()
    

    Note. python3-tk is installed. But not python3.7-tk.

    $ sudo apt install python3.7-tk
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Suggested packages:
      tix python3.7-tk-dbg
    The following NEW packages will be installed:
      python3.7-tk
    0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
    Need to get 143 kB of archives.
    After this operation, 534 kB of additional disk space will be used.
    Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 python3.7-tk amd64 3.7.4-1+xenial2 [143
    kB]
    Fetched 143 kB in 0s (364 kB/s)
    Selecting previously unselected package python3.7-tk:amd64.
    (Reading database ... 256375 files and directories currently installed.)
    Preparing to unpack .../python3.7-tk_3.7.4-1+xenial2_amd64.deb ...
    Unpacking python3.7-tk:amd64 (3.7.4-1+xenial2) ...
    Setting up python3.7-tk:amd64 (3.7.4-1+xenial2) ...
    

    After installing it, all good.

    $ python3
    Python 3.7.4 (default, Sep  2 2019, 20:44:09)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    >>> exit()
    

提交回复
热议问题