How do I import turtle in PyCharm? Keep getting errors

青春壹個敷衍的年華 提交于 2021-02-05 11:45:04

问题


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:

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
----------------------------------------

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

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)".

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 :)


回答1:


SyntaxError at except ValueError, ve: means you're running the code intended for Python 2 under 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.

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).



来源:https://stackoverflow.com/questions/61501339/how-do-i-import-turtle-in-pycharm-keep-getting-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!