“UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm

前端 未结 14 614
梦谈多话
梦谈多话 2020-12-22 18:33

I am trying to plot a simple graph using pyplot, e.g.:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

but the figure

14条回答
  •  囚心锁ツ
    2020-12-22 18:51

    Just in case if this helps anybody.

    Python version: 3.7.7 platform: Ubuntu 18.04.4 LTS

    This came with default python version 3.6.9, however I had installed my own 3.7.7 version python on it (installed building it from source)

    tkinter was not working even when the help('module') shows tkinter in the list.

    The following steps worked for me:

    1. sudo apt-get install tk-dev.

    rebuild the python: 1. Navigate to your python folder and run the checks:

    cd Python-3.7.7
    sudo ./configure --enable-optimizations
    
    1. Build using make command: sudo make -j 8 --- here 8 are the number of processors, check yours using nproc command.
    2. Installing using:

      sudo make altinstall
      

    Don't use sudo make install, it will overwrite default 3.6.9 version, which might be messy later.

    1. Check tkinter now
      python3.7 -m tkinter
      

    A windows box will pop up, your tkinter is ready now.

提交回复
热议问题