【问题标题】:Unable to install python3-tk on Ubuntu 18.04.2 LTS无法在 Ubuntu 18.04.2 LTS 上安装 python3-tk
【发布时间】:2019-05-15 21:14:07
【问题描述】:

我正在运行 Ubuntu 18.04.2 LTS:

user@vmubu01:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic

我无法使用“apt-get install”命令安装 python3-tk,如下所示:

user@vmubu01:~$ sudo apt-get install python3-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  tix python3-tk-dbg
The following NEW packages will be installed:
  python3-tk
0 upgraded, 1 newly installed, 0 to remove and 91 not upgraded.
3 not fully installed or removed.
Need to get 0 B/101 kB of archives.
After this operation, 891 kB of additional disk space will be used.
(Reading database ... 206924 files and directories currently installed.)
Preparing to unpack .../python3-tk_3.6.8-1~18.04_amd64.deb ...
Unpacking python3-tk:amd64 (3.6.8-1~18.04) ...
dpkg: error processing archive /var/cache/apt/archives/python3-tk_3.6.8-1~18.04_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.6/tkinter/__init__.py', which is also in package libpython3.6-stdlib:amd64 3.6.8-1+xenial1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/python3-tk_3.6.8-1~18.04_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我也无法使用 pip 安装它,请参阅下面的错误:

user@vmubu01:~$ pip3.6 install python3-tk
Collecting python3-tk
  ERROR: Could not find a version that satisfies the requirement python3-tk (from versions: none)
ERROR: No matching distribution found for python3-tk

如果我尝试运行“apt --fix-broken install”命令,我会得到:

user@vmubu01:~$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  python3-tk
Suggested packages:
  tix python3-tk-dbg
The following NEW packages will be installed:
  python3-tk
0 upgraded, 1 newly installed, 0 to remove and 91 not upgraded.
3 not fully installed or removed.
Need to get 0 B/101 kB of archives.
After this operation, 891 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 206924 files and directories currently installed.)
Preparing to unpack .../python3-tk_3.6.8-1~18.04_amd64.deb ...
Unpacking python3-tk:amd64 (3.6.8-1~18.04) ...
dpkg: error processing archive /var/cache/apt/archives/python3-tk_3.6.8-1~18.04_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.6/tkinter/__init__.py', which is also in package libpython3.6-stdlib:amd64 3.6.8-1+xenial1
Errors were encountered while processing:
 /var/cache/apt/archives/python3-tk_3.6.8-1~18.04_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

请多指教

【问题讨论】:

  • 帮我个忙,检查/usr/lib/python3.6/tkinter 是否已经存在。它说它在安装时试图覆盖它。
  • 也可以试试sudo apt-get install python3.6-tk
  • @Column01 是的,/usr/lib/python3.6/tkinter 存在,如果我运行 sudo apt-get install python3.6-tk,我会得到完全相同的错误。
  • 这意味着 Tkinter 已经安装。尝试导入并使用它,但确保脚本使用正确的环境
  • @Column01 /usr/bin/python3.6 /home/user/Development/tturtle.py Traceback (most recent call last): File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module> import _tkinter ModuleNotFoundError: No module named '_tkinter'

标签: python-3.x ubuntu-18.04


【解决方案1】:

不确定这个解决方案是否适合所有情况,但这里有一个对我有用。

我遇到了同样的问题(Ubuntu 16.04 除外),还尝试了@Column01 在 cmets 中写的内容:
sudo apt-get install python3.6-tk

同样的问题。 但这给了我一个想法。已检查:

$ python --version
Python 3.5.2

所以解决方案很简单:

sudo apt-get install python3.5-tk

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 2021-08-18
    • 2020-04-17
    • 1970-01-01
    相关资源
    最近更新 更多