python3.7安装turtle,解决Command errored out with exit status 1: python setup.py egg_info Check the logs

介绍

Turtle package(海龟库)是python中使用较为广泛的绘制图像的函数库。导入海龟库之后,我们可以引用海归库中的函数绘制出各种各样的图案,比如哆啦A梦、皮卡丘等。Turtle package的核心思想就是把当前点想象成一个小海龟,然后给小海龟指令,让它沿着指令爬行,沿途留下轨迹就是我们绘制的图形,是不是很有意思呀,听到这估计很多朋友都想尝试一下了。

Python3.7 Turtle安装问题

要想使用Turtle,必须先在自己的计算机上安装Turtle package。由于当时Turtle package刚开始的时候是基于python2发布的,python2和python3在特性上略有不同,所以python3 安装turtle的时候会出现下列错误:
当我们在Anaconda Prompt上安装的时候,输入命令:

pip install -i https://pypi.douban.com/simple turtle

会得到如下错误:

 Complete output (6 lines):
    Traceback (most recent call last):
      File "", line 1, in 
      File "C:\Users\Lei\AppData\Local\Temp\pip-install-8fq2zdd6\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.

解决方法

根据错误信息我们可以推断出是setup.py文件出了问题,因此我们不能直接从源码地址安装turtle,我们要先将turtle下载到本地,然后修改之后进行安装。
下载地址:

https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz

下载完成之后,解压到本地的文件夹。我在这里直接解压在了桌面,如图所示:
python3.7安装turtle,解决Command errored out with exit status 1: python setup.py egg_info Check the logs_第1张图片
下载解压完成之后,我们打开文件夹,找到setup.py文件,使用记事本打开,找到

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

其实就是将except ValueError, ve:加了一个括号,这是由python2和python3之间的版本特性差异决定的。
修改完成之后,我们打开Anaconda Prompt,激活自己的虚拟环境,输入命令:

pip install C:\Users\Lei\Desktop\turtle-0.0.2

注意:install后边的地址是你下载的turtle安装包的所在地址

然后看到打印信息:

Processing c:\users\lei\desktop\turtle-0.0.2
Collecting Twisted>=8.0.1
  Downloading Twisted-20.3.0-cp37-cp37m-win_amd64.whl (3.1 MB)
     |████████████████████████████████| 3.1 MB 2.2 MB/s
Requirement already satisfied: PyYAML>=3.0.8 in d:\anaconda\envs\lei\lib\site-packages (from turtle==0.0.2) (5.3.1)
Collecting PyHamcrest!=1.10.0,>=1.9.0
  Downloading PyHamcrest-2.0.2-py3-none-any.whl (52 kB)
     |████████████████████████████████| 52 kB 167 kB/s
Collecting Automat>=0.3.0
  Downloading Automat-20.2.0-py2.py3-none-any.whl (31 kB)
Requirement already satisfied: attrs>=19.2.0 in d:\anaconda\envs\lei\lib\site-packages (from Twisted>=8.0.1->turtle==0.0.2) (19.3.0)
Collecting hyperlink>=17.1.1
  Downloading hyperlink-20.0.1-py2.py3-none-any.whl (48 kB)
     |████████████████████████████████| 48 kB 409 kB/s
Collecting zope.interface>=4.4.2
  Downloading zope.interface-5.1.0-cp37-cp37m-win_amd64.whl (194 kB)
     |████████████████████████████████| 194 kB 1.1 MB/s
Collecting constantly>=15.1
  Downloading constantly-15.1.0-py2.py3-none-any.whl (7.9 kB)
Collecting incremental>=16.10.1
  Downloading incremental-17.5.0-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: six in d:\anaconda\envs\lei\lib\site-packages (from Automat>=0.3.0->Twisted>=8.0.1->turtle==0.0.2) (1.15.0)
Requirement already satisfied: idna>=2.5 in d:\anaconda\envs\lei\lib\site-packages (from hyperlink>=17.1.1->Twisted>=8.0.1->turtle==0.0.2) (2.10)
Requirement already satisfied: setuptools in d:\anaconda\envs\lei\lib\site-packages (from zope.interface>=4.4.2->Twisted>=8.0.1->turtle==0.0.2) (49.1.0.post20200704)
Building wheels for collected packages: turtle
  Building wheel for turtle (setup.py) ... done
  Created wheel for turtle: filename=turtle-0.0.2-py3-none-any.whl size=24801 sha256=149931a57368833d81bb44b77c98dc3b2ed6421b8f6abe7100f2348cca7f513e
  Stored in directory: c:\users\lei\appdata\local\pip\cache\wheels\03\ae\e4\fb8c9da449e82332d3db9eb89dd5e505221232645b97d811e3
Successfully built turtle
Installing collected packages: PyHamcrest, Automat, hyperlink, zope.interface, constantly, incremental, Twisted, turtle
Successfully installed Automat-20.2.0 PyHamcrest-2.0.2 Twisted-20.3.0 constantly-15.1.0 hyperlink-20.0.1 incremental-17.5.0 turtle-0.0.2 zope.interface-5.1.0

至此,python3.7的turtle就安装成功了。

你可能感兴趣的:(python)