matplotlib error - no module named tkinter

后端 未结 16 1655
被撕碎了的回忆
被撕碎了的回忆 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

    I had the same issue on Win x86/64 because my custom Python3.7 installation did not include Tcl packages, so just modify or re-install your python

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

    0 讨论(0)
  • 2020-11-28 04:25

    you can use

    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    

    if you dont want to use tkinter at all.

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

    EDIT: agg is a different backend like tkinter for matplotlib.

    0 讨论(0)
  • 2020-11-28 04:30

    For Windows users, there's no need to download the installer again. Just do the following:

    1. Go to start menu, type Apps & features,
    2. Search for "python" in the search box,
    3. Select the Python version (e.g. Python 3.8.3rc1(32-bit)) and click Modify,
    4. On the Modify Setup page click Modify,
    5. Tick td/tk and IDLE checkbox (which installs tkinter) and click next.

    Wait for installation and you're done.

    0 讨论(0)
  • 2020-11-28 04:30

    If you are using python 3.6, this worked for me:

    sudo apt-get install python3.6-tk
    

    instead of

    sudo apt-get install python3-tk
    

    Which works for other versions of python3

    0 讨论(0)
  • 2020-11-28 04:30

    Sometimes (for example in osgeo4w distribution) tkinter is removed.

    Try changing matplotlib backend editing matplotlibrc file located in [python install dir]/matplotlib/mpl-data/matplotlibrc changing The backend parameter from backend: TkAgg to something other like backend: Qt4Aggas described here: http://matplotlib.org/faq/usage_faq.html#what-is-a-backend

    0 讨论(0)
  • 2020-11-28 04:33

    If you are using fedora then first install tkinter

    sudo dnf install python3-tkinter
    

    I don't think you need to import tkinter afterwards I also suggest you to use virtualenv

    $ python3 -m venv myvenv
    $ source myvenv/bin/activate
    

    And add the necessary packages using pip

    0 讨论(0)
提交回复
热议问题