Windows下Python3安裝Turtle報錯及解決方案


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,之后等待安裝結束就可以正常使用了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM