我在Ubuntu16.04上有Python3.8。
我安装了python3-tk (在matplotlib中显示地块需要它):
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
和python3.8-tk:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3.8-tk is already the newest version (3.8.2-1+xenial1).
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
但没有找到:
$ python3.8 -m tkinter
Traceback (most recent call last):
File "/usr/local/lib/python3.8/runpy.py", line 184, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/lib/python3.8/runpy.py", line 143, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/local/lib/python3.8/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
安装它的正确方法是什么?
发布于 2020-05-08 06:51:20
重新编译和重新安装python3.8 3.8,用tcl、tk包含和库指定文件夹的路径。
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python-tk python3-tk tk-dev
cd ~/Downloads
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
tar -xvf Python-3.8.2.tgz
cd Python-3.8.2
用下一种方式编辑./configure
文件:替换下一行的...
:
--with-tcltk-includes='-I/usr/include'
--with-tcltk-libs='-L/usr/lib'
./configure
make -j2 # replace 2 by number of processor cores you have
sudo make install
$ python3.8
Python 3.8.2 (default, May 11 2020, 14:30:03)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
在16.04通过apt
和pyenv
安装的Python3.8不包括tkinter,我认为,或者有一些错误不允许导入它。只有重建才有帮助。以前,我在Python3.8版本中使用了20.04版本,它支持tkinter,只安装了16.04版本的Python3.5的附加软件包。
正如Ankur A Sharma所说的那样,python3.8-tk装置也是必需的。我忘了提过了。但这还不够16.04,至少在我的情况下。
“任择议定书”评论中的补充要求:
sudo ./configure --with-tcltk-includes='-I/usr/include -I/usr/include/tcl' --with-tcltk-libs='-L/usr/lib -ltcl -ltk' --enable-optimizations
发布于 2020-08-20 23:00:53
如果您使用apt安装python3.8 (通过ppa:死蛇/ppa),它也可以使用apt安装,库的名称是python3.8-tk
。
sudo apt install python3.8-tk
在我的例子中,它解决了问题。例如,现在我可以在python3.8中使用matplotlib,这需要tkinter。
发布于 2020-05-08 06:53:32
开放终端类型命令
“pip3 3安装tkintertable”
根据您的python版本,可以是pip或pip3。
https://askubuntu.com/questions/1224230
复制相似问题