1. 程式人生 > >python3安裝turtle報錯

python3安裝turtle報錯

python版本:3.7
安裝turtle庫的時候會報錯:

Collecting turtle
  Using cached https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>"
, line 1, in <module> File "/tmp/pip-install-hpqxw6_s/turtle/setup.py", line 40 except ValueError, ve: ^ SyntaxError: invalid syntax ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-
hpqxw6_s/turtle/

仔細檢視安裝turtle出錯的錯誤資訊,可以看到是個語法錯誤。

pip在下載turtle 0.0.2包後,會解壓到本地再安裝,提示的錯誤在解壓的setup.py檔案裡面,

解決的辦法就是:按照給定的連結(turtle 0.0.2),把turtle包下載到本地,手動解壓,修改setup.py檔案再安裝。

1、開啟setup.py檔案,第40行修改為
except (ValueError, ve):
原來的是Python2的寫法,沒有括號,加了括號之後Python3就能用了。

2、用pip3安裝修:
pip3 install -e turtle-0.0.2
-e後面接上我們修改過setup.py檔案的目錄。

這樣就搞定了。