文章目录

  • 问题
  • 第一次尝试——失败
  • 第二次解决——失败
  • 第三次尝试——失败
  • 第四次尝试——换源成功

感觉python3-tk就是个坑,网上的教程看了一大堆,方法也是千奇百怪,估计每个人遇到情况都可能不太一样。以下就将自己的经历贴出来,以供大家参考。


问题

基本上都一样,如下所示

Traceback (most recent call last):File "/home/hadoop/PycharmProjects/wjw/ftdd/ftdd/fdfds2011.py", line 9, in <module>import matplotlib.pyplot as pltFile "/home/hadoop/snap/pycharm-community/venv/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2374, in <module>switch_backend(rcParams["backend"])File "/home/hadoop/snap/pycharm-community/venv/lib/python3.5/site-packages/matplotlib/pyplot.py", line 207, in switch_backendbackend_mod = importlib.import_module(backend_name)File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "/home/hadoop/snap/pycharm-community/venv/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>from . import _backend_tkFile "/home/hadoop/snap/pycharm-community/venv/lib/python3.5/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>import tkinter as TkFile "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

提示要安装python3-tk,接下来就是各种惊喜了…


第一次尝试——失败

开始以为是python自带的库,需要用pip安装。结果搜了一下,竟然没有!

于是网上看了下,大部分都是如下说

tkinter是一个python的接口类库,用以调用tcl/tk程序,故一般在操作系统层面会有相应的类库安装,而非仅仅依靠pip3来安装相应的python类库,比如, python3-tk。


第二次解决——失败

那就直接在系统里安装 python3-tk

sudo apt-get install python3-tk

没有成功,提示如下:

The following packages have unmet dependencies:gnupg : Breaks: software-properties-common (<= 0.96.24.3) but 0.96.20.7 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

网上查了下,说是软件包的依赖问题,要重新安装一下依赖包,输入如下代码:

sudo apt-get install software-properties-common=0.96.24.3

结果没有这个版本的包

E: Version '0.96.24.3' for 'software-properties-common' was not found

网上找了一下,发现有software-properties-common (0.96.24.32.1) ,于是重试了一下:

sudo apt-get install software-properties-common=0.96.24.32.1

结果又出现了新的包依赖问题

The following packages have unmet dependencies:software-properties-common : Depends: python3-software-properties (= 0.96.24.32.1) but 0.96.20.7 is to be installed
E: Unable to correct problems, you have held broken packages.

网上的建议主要有两种:

  • 第一种建议是用aptitude工具
  • 第二种建议是更换软件源

我都试了一下。


第三次尝试——失败

先用大家说的aptitude工具试一试:

sudo apt install aptitude
sudo aptitude install python3-tk

结果是这样:

The following NEW packages will be installed:blt{a} python3-tk python3.6{a} python3.6-minimal{a} tk8.6-blt2.5{a}
The following packages will be upgraded:libpython3-stdlib python3 python3-minimal
3 packages upgraded, 5 newly installed, 0 to remove and 1645 not upgraded.
Need to get 677 kB/2,526 kB of archives. After unpacking 12.5 MB will be used.
The following packages have unmet dependencies:onboard : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-systemd : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-reportlab-accel : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-gi-cairo : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-brlapi : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-pil : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedrhythmbox-plugins : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-uno : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-cups : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-renderpm : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-pycurl : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-cryptography : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedhplip : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-cffi-backend : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-markupsafe : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedtotem-plugins : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-dbus : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-cairo : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-gi : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-lxml : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-gdbm : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedpython3-apt : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installedrhythmbox : Depends: python3 (< 3.6) but 3.6.5-3ubuntu1 is to be installed
The following actions will resolve these dependencies:Keep the following packages at their current version:
1)     libpython3-stdlib [3.5.1-3 (now)]
2)     python3 [3.5.1-3 (now)]
3)     python3-minimal [3.5.1-3 (now)]
4)     python3-tk [Not Installed]

问我接不接受,我当然不接受,准备采用第二种方案,结果

Accept this solution? [Y/n/q/?] n
open: 6453; closed: 16494; defer: 28; conflict: 39                                                                                                                                                       oNo solution found within the allotted time.  Try harder? [Y/n] Y
Resolving dependencies...
open: 13428; closed: 34395; defer: 31; conflict: 43                                                                                                                                                      ONo solution found within the allotted time.  Try harder? [Y/n] Y
Resolving dependencies...
open: 20374; closed: 52401; defer: 32; conflict: 44                                                                                                                                                      .No solution found within the allotted time.  Try harder? [Y/n] n

没有第二种方案???
还出现了这么多新的包依赖问题,在网上查了一下“The following packages have unmet dependencies”这个问题,看到推荐的方法是用“sudo apt-get -f install”来修复,再试一下,结果如下

hadoop@ubun:~$ sudo apt-get install -f
[sudo] password for hadoop:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1633 not upgraded.

再运行一下程序,还是bug,不能解决问题。


第四次尝试——换源成功

参考教程,换了阿里的源,用 sudo vim /etc/apt/sources.list 覆盖了原文件后,执行

$ sudo apt-get update

过程中没出现什么错误,接着执行

$ sudo apt-get install python3-tk

出现如下提示

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:libpython3.6-minimal linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic vim-runtime
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:blt tk8.6-blt2.5
Suggested packages:blt-demo tix python3-tk-dbg
The following packages will be REMOVED:libpython3.6 libpython3.6-stdlib vim
The following NEW packages will be installed:blt python3-tk tk8.6-blt2.5
0 upgraded, 3 newly installed, 3 to remove and 52 not upgraded.
Need to get 604 kB of archives.
After this operation, 13.5 MB disk space will be freed.
Do you want to continue? [Y/n]

确认执行后,没有出现什么问题,将后面的内容一并贴出来

Do you want to continue? [Y/n] y
Get:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 blt amd64 2.5.3+dfsg-3 [4,852 B]
Get:1 http://172.21.0.162/files/2063000000025039/us.archive.ubuntu.com/ubuntu xenial/main amd64 tk8.6-blt2.5 amd64 2.5.3+dfsg-3 [574 kB]
Get:3 http://mirrors.aliyun.com/ubuntu xenial/main amd64 python3-tk amd64 3.5.1-1 [25.1 kB]
Fetched 604 kB in 0s (2,033 kB/s)
(Reading database ... 266539 files and directories currently installed.)
Removing vim (2:8.0.1453-1ubuntu1) ...
update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/rview (rview) in auto mode
Removing libpython3.6:amd64 (3.6.6-1~18.04) ...
Removing libpython3.6-stdlib:amd64 (3.6.6-1~18.04) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
/sbin/ldconfig.real: /usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic linkSelecting previously unselected package tk8.6-blt2.5.
(Reading database ... 266175 files and directories currently installed.)
Preparing to unpack .../tk8.6-blt2.5_2.5.3+dfsg-3_amd64.deb ...
Unpacking tk8.6-blt2.5 (2.5.3+dfsg-3) ...
Selecting previously unselected package blt.
Preparing to unpack .../blt_2.5.3+dfsg-3_amd64.deb ...
Unpacking blt (2.5.3+dfsg-3) ...
Selecting previously unselected package python3-tk.
Preparing to unpack .../python3-tk_3.5.1-1_amd64.deb ...
Unpacking python3-tk (3.5.1-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
/sbin/ldconfig.real: /usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic linkSetting up tk8.6-blt2.5 (2.5.3+dfsg-3) ...
Setting up blt (2.5.3+dfsg-3) ...
Setting up python3-tk (3.5.1-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
/sbin/ldconfig.real: /usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic linkhadoop@ubun:/etc/apt/sources.list.d$

最后,运行一下python代码,终于OK了!

(开心一秒,谁知道下个bug是什么呢…)

Ubuntu安装python3-tk相关推荐

  1. centos/Ubuntu安装python3.7.0安装mysql5.7/5.6

    Python3.7 1. 下载安装所需要的包,不然安装时或者以后使用python时报错 yum install -y libffi-devel zlib-devel bzip2-devel opens ...

  2. ubuntu安装python3(源码安装方法)

    Ubuntu安装Python3 (第0步)建议配置阿里镜像https://developer.aliyun.com/mirror/ubuntu 一.安装相关依赖 apt-get update & ...

  3. ubuntu安装python3.6_Ubuntu上安装python3.6以及多版本python管理 | SQN

    这篇文章记录了如何在Ubuntu上安装python3.6以及将其设置为系统默认. 查看Ubuntu版本 由于python3.6在不同的Ubuntu版本中的安装是不一样的,这里我们先来看一下的Ubunt ...

  4. ubuntu安装python3.6_Ubuntu16.04安装python3.6.5步骤详解

    下载python3.6.5安装包 1. 上传安装包.打开终端,利用命令cd 进入文件所在文件夹里 python@ubuntu:~/workspace$pwd /home/python/workspac ...

  5. Ubuntu安装python3.7.5(附加更新python默认指向为python3.7)

    我的环境:Ubuntu16.04 + Ptyhon3.7.5 之前写过CentOS系统安装Python,本以为Ubuntu下和CentOS下安装步骤差不多,没想到不太一样,所以更新一篇Ubuntu下安 ...

  6. ubuntu安装python3.6失败 出现403 Forbidden错误

    ubuntu安装python失败 Err:8 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial Release 403 Forbi ...

  7. ubuntu安装python3.6

    首先从python网站下载源码自己编译安装,本例子下载的是Python3.6.11. 下载之后,是个名为Python-3.6.11.tgz的压缩包,直接解压. 里头有个README.rst使用说明: ...

  8. 乌班图安装python_优麒麟/Ubuntu安装Python3

    虚拟环境: Python:Python3.7.3(Python-3.7.3.tgz) 系统源为阿里源:http://mirrors.aliyun.com/ubuntu 一.下载软件 官网下载:http ...

  9. Ubuntu安装Python3.8

    一.安装Python3.8 Ubuntu 官方 apt 库中还未收录 python 3.8,这里使用 deadsnakes PPA 软件源安装. 1.安装依赖包 $ sudo apt-get upda ...

  10. Ubuntu安装python3.10.6

    Ubuntu 16.04安装python 3.10.6(通过源码安装)详细教程 最近学习python,想在Ubuntu下使用pycharm,发现pycharm不支持python3.5的解释器,就必须安 ...

最新文章

  1. 课程表美化 css_通过这门11小时的免费课程学习HTML和CSS
  2. linux cuda 异常退出,cudaErrorCudartUnloading问题排查及建议方案
  3. JAVA常用知识总结(七)——Spring
  4. 学计算机须知,学习计算机须知的50个专业术语
  5. 深入Android 【六】 —— 界面构造
  6. 视图插入数据_SAP Fiori的ABAP编程模型-CDS视图创建
  7. SQLite 入门教程(四)增删改查,有讲究
  8. Linux 搜狗输入法 候选字乱码
  9. Linux性能分析工具与图形化方法
  10. Java 8 Friday Goodies:SQL ResultSet流
  11. 在一个禁止离婚的国家结婚
  12. datatable使用groupby进行分组统计 .
  13. 真实赛车3,SPEEDRUSH TV 第3季,第3阶段(第3天),直线加速赛
  14. [学习笔记]0/1分数规划
  15. PHP之 直播开发后端需要做什么——准备工作
  16. OpenCV概述及安装配置教程
  17. cdr怎么转plt_win10系统怎么将cdr格式转换成plt?
  18. 用户管理及权限管理的意义
  19. 软件开发工具【十四】 之 常用建模工具
  20. 免费申请ssl证书并部署

热门文章

  1. matplotlib中文乱码解决及plt.rcParams参数的使用
  2. php csrf攻击,常见的CSRF攻击的原理,让我们一起来了解一下!
  3. curl命令实现上网认证登录
  4. 在element dialog中使用天地图报错Error in v-on handler: “TypeError: Cannot read property ‘_tdt_events‘ of null
  5. pdf文件怎么删除其中一页或几页内容
  6. 计算机专业全套教材pdf,计算机 5教材.pdf
  7. 微信支付宝个人免签约收款系统的实现
  8. 全电发票这么好,但如何做才能真正享受其释放的价值效能?
  9. 30000亿市场规模亟待挖掘,适老化改造机遇和突破口在哪里?
  10. 【acwing 寒假每日一题(入门组)】day24数独检查