大神们 帮忙看看这是什么错误 在线急等

2020-01-01 15:10:33 +08:00
 victory

没有任何编程知识的小白 最近在自学 Python 学习 turtle 中

一开始是 Python 3.8.1 x64 win10 x64 代码

from turtle import *
color("red", "green")
shape("turtle")
done()

参考文档 https://docs.python.org/zh-cn/3.8/library/turtle.html

运行报错

Traceback (most recent call last):
  File "C:/Python/test.py", line 1, in <module>
    from turtle import *
  File "C:/Python\turtle.py", line 3, in <module>
    color("red", "blue")
NameError: name 'color' is not defined

难道环境配置错了? 后来注册了 cloud studio 预置环境是 Python 2.7 x64 Ubuntu 18.04 代码

import turtle
turtle.color("red", "green")
turtle.shape("turtle")

参考文档 https://docs.python.org/zh-cn/2.7/library/turtle.html

还是运行错误 我要裂开了

cd /root/workspace ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/bin/python /root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 41197 /root/workspace/python2_turtle.py 
Traceback (most recent call last):
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/lib/python/ptvsd/__main__.py", line 434, in main
    run()
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/lib/python/ptvsd/__main__.py", line 312, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/lib/python2.7/runpy.py", line 252, in run_path
    return _run_module_code(code, init_globals, run_name, path_name)
  File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/root/workspace/python2_turtle.py", line 1, in <module>
    import turtle
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
    import Tkinter as TK
  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
➜  workspace cd /root/workspace ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/bin/python /root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 48877 /root/workspace/python2_turtle.py 
Traceback (most recent call last):
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/lib/python/ptvsd/__main__.py", line 434, in main
    run()
  File "/root/.local/share/code-server/extensions/ms-python.python-2019.6.24221/pythonFiles/lib/python/ptvsd/__main__.py", line 312, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/lib/python2.7/runpy.py", line 252, in run_path
    return _run_module_code(code, init_globals, run_name, path_name)
  File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/root/workspace/python2_turtle.py", line 1, in <module>
    import turtle
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
    import Tkinter as TK
  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
3944 次点击
所在节点    Python
25 条回复
crella
2020-01-01 18:09:28 +08:00
楼主为什么不在 python3 的交互式环境先试一下逐行运行代码呢?
crella
2020-01-01 18:15:38 +08:00
@victory 看来你对面向对象的编程语言没有一个基本的认识,建议先快速学习一下菜鸟教程的 c#教程,然后浏览一本讲 c#的书。或者学一下基本的 java。

python 虽然方便,但是如果你对现代编程语言没个基本的了解的话,以后碰到这样的坑只会越来越多。学一下 c#或者 java 能够让你知道 python 等脚本语言在哪些地方帮你做了哪些事情,还有避免死循环等等。

也不需要学得多深入,看得懂线程 Thread 以前的章节就行了,包括文件系统访问。也不需要背代码哈~
crella
2020-01-01 18:28:04 +08:00
楼上的提示至少包含全局函数、导入包、linux 安装包等等,很多东西不是看 python 官方文档就能解决的。

作为世界上最强的 ide:visual studio,还有免费版,语法错误自动提示,简单到爆的调试。先搞明白吧。然后用 python 快速建造自己想要的工具。
XavierXJ
2020-01-02 01:16:02 +08:00
楼主你可以去听一下中国慕课大学网陈斌老师那个 Python 入门课,对小白很友好,当然也是免费的,本人也是非专业学习,纯属好心推荐。加油!坚持下去
noqwerty
2020-01-02 15:17:16 +08:00
新的一年感觉 V 站变得友善了😂

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/634176

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX