V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
victory
V2EX  ›  Python

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

  •  1
     
  •   victory · 2020-01-01 14:19:40 +08:00 · 3566 次点击
    这是一个创建于 1792 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    一开始是 Python 3.8.1

    form turtle import *
    color("red", "greed"}
    shape("turtle")
    done()
    
    jdhao
        1
    jdhao  
       2020-01-01 14:31:07 +08:00 via Android
    dangyuluo
        2
    dangyuluo  
       2020-01-01 14:55:56 +08:00
    你第一句话(仅限空格之前)说的挺对的
    victory
        3
    victory  
    OP
       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
        4
    Sylv  
       2020-01-01 15:12:48 +08:00 via iPhone
    运行报错请发报错信息,要不然让大家盲猜?
    victory
        5
    victory  
    OP
       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
        6
    Sylv  
       2020-01-01 15:23:52 +08:00 via iPhone
    自己创建的 turtle.py 文件改个名,和 turtle 库重名了。
    victory
        7
    victory  
    OP
       2020-01-01 15:25:06 +08:00
    @Sylv 改了文件名一样报错
    zanelee
        8
    zanelee  
       2020-01-01 15:46:22 +08:00
    @victory py2 是因为没装 python-tk 这个库吧。py3 直接 import turtle 不行吗?你 turtle 库安装了吗?我看 py3 里 pip install 安装 turtle 的时候得下载包吧 setup.py 改一下才能装。
    victory
        9
    victory  
    OP
       2020-01-01 15:55:20 +08:00
    @zanelee 额 turtle 是内置模块 or 自带的标准库 不需要安装吧
    Python3 为什么那么写 因为 官方参考文档就是那么写的 docs.python.org/zh-cn/3.8/library/turtle.html
    mochanight
        10
    mochanight  
       2020-01-01 18:06:02 +08:00
    import turtle
    turtle.color("red", "green")
    turtle.shape("turtle")
    done()
    mochanight
        11
    mochanight  
       2020-01-01 18:07:32 +08:00
    import turtle
    turtle.color("red", "green")
    turtle.shape("turtle")
    turtle.done()
    ylrshui
        12
    ylrshui  
       2020-01-01 18:37:51 +08:00 via iPhone
    先 form -> from
    yangzzzzzzzt1
        13
    yangzzzzzzzt1  
       2020-01-01 20:01:41 +08:00
    ( }
    zanelee
        14
    zanelee  
       2020-01-01 20:17:12 +08:00
    @victory ==,看了下库还真是自带的,直接 import turtle,然后和下面 py2 的时候写法一样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3621 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:45 · PVG 18:45 · LAX 02:45 · JFK 05:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.