Я использую виртуальную среду с 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 уже установлен.Что я должен делать?Я проверил 'ask ubuntu' или 'stackoverflow', но не смог найти справку, которая мне подходит (пробовал pip install tkinter
, но получил сообщение could not find version that satisfies..
)