1. 程式人生 > >Python3安裝turtle報錯 File “/tmp/pip-install-hpqxw6_s/turtle/setup.py”, line 40

Python3安裝turtle報錯 File “/tmp/pip-install-hpqxw6_s/turtle/setup.py”, line 40

Python3.5安裝turtle:

pip3 install 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 “”, line 1, in
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包下載到本地,手動解壓,修改setup.py檔案再安裝。

開啟setup.py檔案,第40行修改為

 except (ValueError, ve):

原來的是Python2的寫法,沒有括號,加了括號之後Python3就能用了。
用pip3安裝修:

 pip install -e turtle-0.0.2

-e後面接上我們修改過setup.py檔案的目錄。
這樣就搞定了。

另外,如果提示 python-tk 未安裝,用apt命令安裝就可以了:

sudo apt install python-tk

轉載自:https://oomake.com/question/178949