转自https://www.cnblogs.com/yangqi199808/p/13352900.html
Turtle安装
在Windows下Python3安装会提示如下报错:
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting turtle
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz (11 kB)
ERROR: Command errored out with exit status 1:
command: 'D:\Programs\Python\Python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Yankee\\AppData\\Local\\Temp\\pycharm-packaging\\turtle\\setup.py'"'"'; __file__='"'"'C:\\Users\\Yankee\\AppData\\Local\\Temp\\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 'C:\Users\Yankee\AppData\Local\Temp\pycharm-packaging\turtle\pip-egg-info'
cwd: C:\Users\Yankee\AppData\Local\Temp\pycharm-packaging\turtle\
Complete output (6 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Yankee\AppData\Local\Temp\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.
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the 'D:\Programs\Python\Python37\python.exe -m pip install --upgrade pip' command.
根据自己的错误提示中的位置下载turtle-0.0.2.tar.gz
包,比如我的是https://pypi.tuna.tsinghua.edu.cn/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
,下载好之后解压,修改其中的的setup.py
文件第40行
- 原代码
def pluginModules(moduleNames):
from twisted.python.reflect import namedAny
for moduleName in moduleNames:
try:
yield namedAny(moduleName)
except ImportError:
pass
except ValueError, ve:
if ve.args[0] != 'Empty module name':
traceback.print_exc()
except:
traceback.print_exc()
- 修改后的代码
def pluginModules(moduleNames):
from twisted.python.reflect import namedAny
for moduleName in moduleNames:
try:
yield namedAny(moduleName)
except ImportError:
pass
except (ValueError, ve):
if ve.args[0] != 'Empty module name':
traceback.print_exc()
except:
traceback.print_exc()
其实造成这个错误的原因是因为Python2中的语法可以没有括号,但是在Python3中如果没有括号就会报错,所以添加括号后就可以使用pip install 文件路径
安装了。
打开cmd执行pip install 文件路径
,比如我的位置就是pip install G:\Desktop\turtle-0.0.2
,之后等待安装结束就可以正常使用了。