[PYTHON] When import matplotlib.pyplot cannot be done in pyenv-virtualenv environment

environment

OS:ubuntu14.04 LTS pyenv virtualenv 3.5.2 xxx to build python3 environment afterwards, pip install matplotlib Install matplotlib with: No problem so far. Dohama from here. In a dialogue environment >>>import matplotlib.pyplot When you do

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/six.py", line 92, in __get__
    result = self._resolve()
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/user/.pyenv/versions/pyenv3.5.2/lib/python3.5/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/home/user/.pyenv/versions/3.5.2/lib/python3.5/tkinter/__init__.py", line 35, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

I get an error like this and can't take a step forward. I searched various sites and rewritten the backend of matplotlibrc, I tried putting in freetype and libpng, but it didn't work at all.

Conclusion

Change the version of matplotlib. If you check with pip freeze etc. and it is matplotlib == 2.0.0,

(xxx)pip uninstall matplotlib
(xxx)pip install matplotlib==1.4.3 * xxx is the virtualenv environment name

Try installing the previous version with. In my case, this succeeded in ʻimport of matplotlib.pyplot`.

Reference: matplotlib.pyplot stopped working well with version 1.5.0 @Mac

Recommended Posts

When import matplotlib.pyplot cannot be done in pyenv-virtualenv environment
Investigation when import cannot be done with python
Python environment settings (virtualenv + pip cannot be done)
Matplotlib etc. cannot be imported in VirtualEnv environment
When USB cannot be formatted
When pydub cannot be installed
Master the type in Python? (When should type check be done)
Video cannot be loaded with Spyder in Python development environment
Django cannot be installed in the development environment of pipenv + pyenv
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
Measures that pip install cannot be done with pycharm or import ssl cannot be done
Solution when aws-cli cannot be executed on Mac virtual environment (after installing Python 3.8)
When I name the file flask.py in Flask, I get Import Error: cannot import name'Flask'
Measures to be taken when "Cannot open display" is displayed in X11 Forward
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
When Html cannot be output with Jupyter Notebook
"Temporary solution" when pip cannot be updated [Python]
[Linux] When "| (pipe)" cannot be hit on CentOS7
Precautions when installing packages in the conda environment
Could not import C error in GO environment
[Django] css in the project cannot be read
Use pydantic when reading environment variables in Python