先祝福大家新年快乐 Python 大神们 帮忙看看是什么问题

2020-01-01 14:19:40 +08:00
 victory

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

一开始是 Python 3.8.1

form turtle import *
color("red", "greed"}
shape("turtle")
done()
3559 次点击
所在节点    Python
14 条回复
jdhao
2020-01-01 14:31:07 +08:00
dangyuluo
2020-01-01 14:55:56 +08:00
你第一句话(仅限空格之前)说的挺对的
victory
2020-01-01 15:09:34 +08:00
@jdhao 新手不懂 V2EX 编辑器 误点击发布了 问题没有编辑好就发布出来了
没有任何编程知识的小白 最近在自学 Python 学习 turtle 中

一开始是 Python 3.8.1 x64 win10 x64
代码
```Python
form turtle import *
color("red", "green")
shape("turtle")
done()
```
参考文档
https://docs.python.org/zh-cn/3.8/library/turtle.html

运行报错

难道环境配置错了?
后来注册了 cloud studio 预置环境是 Python 2.7 x64 Ubuntu
代码
```Python
import turtle
turtle.color("red", "green")
turtle.shape("turtle")
```
参考文档
https://docs.python.org/zh-cn/2.7/library/turtle.html

还是运行错误 我要裂开了
Sylv
2020-01-01 15:12:48 +08:00
运行报错请发报错信息,要不然让大家盲猜?
victory
2020-01-01 15:15:31 +08:00
@Sylv
Python 3 的错误提示
```Python
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
```
Python 2.7 的错误提示
```Python
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
```
Sylv
2020-01-01 15:23:52 +08:00
自己创建的 turtle.py 文件改个名,和 turtle 库重名了。
victory
2020-01-01 15:25:06 +08:00
@Sylv 改了文件名一样报错
zanelee
2020-01-01 15:46:22 +08:00
@victory py2 是因为没装 python-tk 这个库吧。py3 直接 import turtle 不行吗?你 turtle 库安装了吗?我看 py3 里 pip install 安装 turtle 的时候得下载包吧 setup.py 改一下才能装。
victory
2020-01-01 15:55:20 +08:00
@zanelee 额 turtle 是内置模块 or 自带的标准库 不需要安装吧
Python3 为什么那么写 因为 官方参考文档就是那么写的 docs.python.org/zh-cn/3.8/library/turtle.html
mochanight
2020-01-01 18:06:02 +08:00
import turtle
turtle.color("red", "green")
turtle.shape("turtle")
done()
mochanight
2020-01-01 18:07:32 +08:00
import turtle
turtle.color("red", "green")
turtle.shape("turtle")
turtle.done()
ylrshui
2020-01-01 18:37:51 +08:00
先 form -> from
yangzzzzzzzt1
2020-01-01 20:01:41 +08:00
( }
zanelee
2020-01-01 20:17:12 +08:00
@victory ==,看了下库还真是自带的,直接 import turtle,然后和下面 py2 的时候写法一样

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

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

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

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

© 2021 V2EX