无法使用“请安装python-tk”消息导入matplotlib.pyplot

时间:2019-03-01 11:41:20

标签: python matplotlib tkinter

我在python 2.7中使用虚拟环境。 (Ubuntu 16.04.5 LTS) 当我做import matplotlib.pyplot as plt时,下面会出现错误。

(venv2) ckim@chan-ubuntu:~$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ckim/venv2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/ckim/venv2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/home/ckim/venv2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
    from . import tkagg  # Paint image to Tk photo blitter extension.
  File "/home/ckim/venv2/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
    from six.moves import tkinter as Tk
  File "/home/ckim/venv2/lib/python2.7/site-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/home/ckim/venv2/lib/python2.7/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/ckim/venv2/lib/python2.7/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package

当我尝试安装python-tk时,出现此错误:

(venv2) ckim@chan-ubuntu:~/venv2$ pip install python-tk
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting python-tk
  Could not find a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk

认为新的pip可以识别python-tk,我尝试在虚拟环境中更新pip,

(venv2) ckim@chan-ubuntu:~/venv2$ sudo pip install --upgrade pip
The directory '/home/ckim/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ckim/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 876kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-19.0.3

使用升级的点(19.0.3),可以得到相同的结果。

(venv2) ckim@chan-ubuntu:~/venv2$ pip --version
pip 19.0.3 from /home/ckim/venv2/lib/python2.7/site-packages/pip (python 2.7)
(venv2) ckim@chan-ubuntu:~/venv2$ pip install python-tk
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting python-tk
  Could not find a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk

然后我取消了virutla环境,并在系统中安装python-tk

ckim@chan-ubuntu:~/venv2$ sudo apt-get install python-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-tk is already the newest version (2.7.12-1~16.04).
0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.

因此,它说已经安装了ppython-tk。我该怎么办?我检查了“询问ubuntu”或“ stackoverflow”,但找不到对我有用的任何帮助。(尝试pip install tkinter但收到could not find version that satisfies..消息)

0 个答案:

没有答案