您尚未登录。

楼主 #1 2019-10-06 07:52:33

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Ubuntu18.04 python 解释器下import 乌龟库turtle出错

$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/turtle.py", line 107, in <module>
    import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
>>> quit()

离线

楼主 #2 2019-10-06 07:56:23

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: Ubuntu18.04 python 解释器下import 乌龟库turtle出错

sudo apt install python3-pip

$ sudo pip3 install tkinter
The directory '/home/whycan/.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/whycan/.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 tkinter
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python3/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/tkinter/

装不了 tkinter

离线

楼主 #3 2019-10-06 08:27:53

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: Ubuntu18.04 python 解释器下import 乌龟库turtle出错

$ sudo apt-get install python3-tk 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  fonts-liberation2 fonts-opensymbol gir1.2-geocodeglib-1.0 gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gir1.2-gudev-1.0
  gir1.2-udisks-2.0 grilo-plugins-0.3-base gstreamer1.0-gtk3 libboost-date-time1.65.1 libboost-filesystem1.65.1 libboost-iostreams1.65.1
  libboost-locale1.65.1 libcdr-0.1-1 libclucene-contribs1v5 libclucene-core1v5 libcmis-0.5-5v5 libcolamd2 libdazzle-1.0-0 libe-book-0.1-1
  libedataserverui-1.2-2 libeot0 libepubgen-0.1-1 libetonyek-0.1-1 libevent-2.1-6 libexiv2-14 libfreerdp-client2-2 libfreerdp2-2 libgc1c2
  libgee-0.8-2 libgexiv2-2 libgom-1.0-0 libgpgmepp6 libgpod-common libgpod4 liblangtag-common liblangtag1 liblirc-client0 liblua5.3-0
  libmediaart-2.0-0 libmspub-0.1-1 libodfgen-0.1-1 libqqwing2v5 libraw16 librevenge-0.0-0 libsgutils2-2 libssh-4 libsuitesparseconfig5
  libvncclient1 libwinpr2-2 libxapian30 libxmlsec1 libxmlsec1-nss lp-solve media-player-info python3-mako python3-markupsafe syslinux
  syslinux-common syslinux-legacy usb-creator-common
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:
  blt libtcl8.6 libtk8.6 tk8.6-blt2.5
建议安装:
  blt-demo tcl8.6 tk8.6 tix python3-tk-dbg
下列【新】软件包将被安装:
  blt libtcl8.6 libtk8.6 python3-tk tk8.6-blt2.5
升级了 0 个软件包,新安装了 5 个软件包,要卸载 0 个软件包,有 3 个软件包未被升级。
需要下载 2,252 kB 的归档。
解压缩后会消耗 9,233 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libtcl8.6 amd64 8.6.8+dfsg-3 [881 kB]
获取:2 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libtk8.6 amd64 8.6.8-4 [693 kB]
获取:3 http://mirrors.aliyun.com/ubuntu bionic/main amd64 tk8.6-blt2.5 amd64 2.5.3+dfsg-4 [572 kB]
获取:4 http://mirrors.aliyun.com/ubuntu bionic/main amd64 blt amd64 2.5.3+dfsg-4 [4,944 B]
获取:5 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 python3-tk amd64 3.6.8-1~18.04 [101 kB]
已下载 2,252 kB,耗时 1秒 (1,551 kB/s)
正在选中未选择的软件包 libtcl8.6:amd64。
(正在读取数据库 ... 系统当前共安装有 156569 个文件和目录。)
正准备解包 .../libtcl8.6_8.6.8+dfsg-3_amd64.deb  ...
正在解包 libtcl8.6:amd64 (8.6.8+dfsg-3) ...
正在选中未选择的软件包 libtk8.6:amd64。
正准备解包 .../libtk8.6_8.6.8-4_amd64.deb  ...
正在解包 libtk8.6:amd64 (8.6.8-4) ...
正在选中未选择的软件包 tk8.6-blt2.5。
正准备解包 .../tk8.6-blt2.5_2.5.3+dfsg-4_amd64.deb  ...
正在解包 tk8.6-blt2.5 (2.5.3+dfsg-4) ...
正在选中未选择的软件包 blt。
正准备解包 .../blt_2.5.3+dfsg-4_amd64.deb  ...
正在解包 blt (2.5.3+dfsg-4) ...
正在选中未选择的软件包 python3-tk:amd64。
正准备解包 .../python3-tk_3.6.8-1~18.04_amd64.deb  ...
正在解包 python3-tk:amd64 (3.6.8-1~18.04) ...
正在设置 libtcl8.6:amd64 (8.6.8+dfsg-3) ...
正在设置 libtk8.6:amd64 (8.6.8-4) ...
正在设置 tk8.6-blt2.5 (2.5.3+dfsg-4) ...
正在设置 blt (2.5.3+dfsg-4) ...
正在设置 python3-tk:amd64 (3.6.8-1~18.04) ...
正在处理用于 libc-bin (2.27-3ubuntu1) 的触发器 ...

搞定了, 原来是姿势用错了, 正确的是: sudo apt-get install python3-tk

离线

楼主 #4 2019-10-09 21:25:59

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: Ubuntu18.04 python 解释器下import 乌龟库turtle出错

import turtle
turtle.clear()
turtle.goto(0,0)
turtle.forward(100);turtle.right(144)
turtle.forward(100);turtle.right(144)
turtle.forward(100);turtle.right(144)
turtle.forward(100);turtle.right(144)
turtle.forward(100);turtle.right(144)

2019-10-09_21-23-04屏幕截图.png

画个五角星试一试。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn