如何在 PyCharm 中导入海龟?不断收到错误 [英] How do I import turtle in PyCharm? Keep getting errors

查看:85
本文介绍了如何在 PyCharm 中导入海龟?不断收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对于 Python 初学者课程,我需要在我的 Mac 上安装 python3(它在 Python 2.7.x 上运行 - x 表示一些我不记得的数字,但我认为这在这里不重要).我有一个设置安装指南——尽管它是为 Windows 设计的——它包括以下步骤:- 安装蟒蛇 3.- 完成下载后,在显示时勾选 Add Python 3.7 to PATH 框(它没有显示在我在 Mac 上的向导安装中)- 安装 PyCharm- 在新项目中,选择 Python 3.7 作为 Base Interpreter- 要检查您的安装是否成功,请转到终端并输入 python --version(尽管安装了 Python 3,但我的仍然是 Python 2.7).我发现问题是我需要更改 Python 的 PATH 但我对终端不是很满意并且无法弄清楚如何更改它 - 在这里完全是初学者.所以我安装了 Anaconda,它为我完成了整个事情,然后出于某种原因(这里完全是初学者!)我发现自己在 PyCharm 上有两个解释器:Python 3.7 和 3.8.PyCharm 可以与它​​们一起使用.当我需要将乌龟导入 Pycharm 并且它不断给我错误时,问题就出现了.这是命令输出:

So for a beginner python course, I needed to install python3 on my Mac (which was running on Python 2.7.x - x meaning some number I can't recall but I dont think it matters here). I had a setup installation guide - which was meant for windows though - which included the following steps: - Install python 3. - At complete download, tick the ​Add Python 3.7 to PATH​ box when it is shown (which it didnt show on my wizard installation on Mac) - Install PyCharm - On new project, select Python 3.7 as Base Interpreter - To check that your installation is successful, go to terminal and type python --version (mine kept being Python 2.7 despite having Python 3 installed). I figured out the problem was I needed to change the PATH for Python but I am not very comfortable with the terminal and couldnt figure out how to change that - total beginner here. So I installed Anaconda who did the whole thing for me and then for some reason (total beginner here!) I found myself with two interpreters on PyCharm: Python 3.7 and 3.8. PyCharm works with both of them. The problem comes when I need to import turtle into Pycharm and it keeps giving me errors. This is the command output:

收集海龟使用缓存的turtle-0.0.2.tar.gz (11 kB)

Collecting turtle Using cached turtle-0.0.2.tar.gz (11 kB)

ERROR: Command errored out with exit status 1:
 command: /Users/xxxxxx/Documents/projects/cfg-python/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/lg/s5jdvb7j5zldn8pd1nfcrn580000gn/T/pycharm-packaging/turtle/setup.py'"'"'; __file__='"'"'/private/var/folders/lg/s5jdvb7j5zldn8pd1nfcrn580000gn/T/pycharm-packaging/turtle/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/lg/s5jdvb7j5zldn8pd1nfcrn580000gn/T/pip-pip-egg-info-crzjvqnl
     cwd: /private/var/folders/lg/s5jdvb7j5zldn8pd1nfcrn580000gn/T/pycharm-packaging/turtle/
Complete output (6 lines):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/lg/s5jdvb7j5zldn8pd1nfcrn580000gn/T/pycharm-packaging/turtle/setup.py", line 40
    except ValueError, ve:
                     ^
SyntaxError: invalid syntax
----------------------------------------

错误:命令出错,退出状态为 1:python setup.py egg_info 检查日志以获取完整的命令输出.

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

在建议的解决方案"下,它还说明了以下内容:尝试从系统终端运行此命令.确保为位于/Users/xxxxxx/Documents/projects/cfg-python/venv/bin/python"的 Python 解释器安装了正确版本的pip".另外,如果我在终端中输入 pip --version ,它会显示来自/opt/anaconda3/lib/python3.7/site-packages/pip (python 3.7) 的 pip 20.1".

Under "proposed solution" it also says the following: Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at '/Users/xxxxxx/Documents/projects/cfg-python/venv/bin/python'. Also if I type pip --version into the terminal it says "pip 20.1 from /opt/anaconda3/lib/python3.7/site-packages/pip (python 3.7)".

我目前使用 Python 3.8 的最新版本的 pip (20.1) 作为项目解释器 - 但也许我需要更改它?问题是当我尝试为 Python 3.7 PyCharm 安装打包工具时说无效的 Python SDK - 并且具体来说"无法运行程序/Users/xxxxxx/Desktop/Coding/CFG 2/cfg-python/venv/bin/python"(在目录 "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers"): error=2, No such file or directory" .过去四个小时我一直在谷歌搜索,似乎真的不能想出来,所以我希望你们能帮我.希望我已经给了你所有必要的信息来解决它.谢谢!Ps.无论你需要解释什么,特别是涉及终端,就像你在和一个人说话一样请五岁:)

I am currently using the latest version of pip (20.1) for Python 3.8 as Project Interpreter - but maybe I need to change it? Problem is when I try to install packaging tools for Python 3.7 PyCharm says "Invalid Python SDK - and as specifics "Cannot run program "/Users/xxxxxx/Desktop/Coding/CFG 2/cfg-python/venv/bin/python" (in directory "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers"): error=2, No such file or directory" . I have been googling for the past four hours and really can't seem to figure it out so I hope you guys will for me. Hope I have given you all the necessary info to solve it. Thank you! Ps. Whatever you need to explain, especially involving the terminal, do it like you're talking to a five year old please :)

推荐答案

SyntaxError at except ValueError, ve: 表示您正在运行用于 Python 2 下的代码Python 3.

SyntaxError at except ValueError, ve: means you're running the code intended for Python 2 under Python 3.

让我们看看.turtle 0.0.2 于 2009 年 6 月 12 日发布,状态:测试版.该项目显然太旧了,被废弃了.我不确定它甚至可以在 Python 2.7 下运行,当然不能在 Python 3 下运行.

Let's see. turtle 0.0.2 released at Jun 12, 2009, status: beta. The project is obviously too old and abandoned. I'm not sure it could be run even under Python 2.7, certainly not under Python 3.

也许你需要一个不同的海龟,标准库中的那个?您可能不需要安装它,您应该使用 Python 安装它(尽管有些发行版将标准库拆分为多个部分).

Perhaps you need a different turtle, the one in the standard library? You probably don't need to install it, you should have it installed with Python (though some distributions split the standard library into pieces).

这篇关于如何在 PyCharm 中导入海龟?不断收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆