%20%E5%87%BA%E9%8C%AF.png)
安裝時出現以下錯誤turtle
,我該怎麼辦?
$ sudo pip install turtle --proxy http://10.144.1.10:8080
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting turtle
Using cached https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-smo98rwf/turtle/setup.py", line 40
except ValueError, ve:
^
SyntaxError: invalid syntax
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-smo98rwf/turtle/
我使用的是 Fedora 31,pip 版本:
$ pip --version
pip 19.1.1 from /usr/lib/python3.7/site-packages/pip (python 3.7)
其他一些Python庫可以成功安裝,例如:
$ sudo pip install scipy --proxy http://10.144.1.10:8080
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting scipy
Downloading https://files.pythonhosted.org/packages/37/9d/a606dc7b17ef0b7326afd128e132b7a483d5611da603334842df75d92d3c/scipy-1.4.0-cp37-cp37m-manylinux1_x86_64.whl (26.1MB)
|████████████████████████████████| 26.1MB 824kB/s
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib64/python3.7/site-packages (from scipy) (1.17.4)
Installing collected packages: scipy
Successfully installed scipy-1.4.0
順便說一句,海龜似乎沒有安裝在我的蟒蛇中...
$ python
Python 3.7.5 (default, Dec 15 2019, 17:54:26)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'turtle'
>>>
概括:
turtle graphics
是python3標準函式庫的一部分,無需安裝。如果import turtle
顯示類似「沒有名為...的模組」的錯誤,可以透過以下方式解決:例如在 Fedora 中,sudo dnf install python3-tkinter
答案1
海龜圖形已經包含在Python標準庫中。
還要安裝python3-tkinter來自預設 Fedora 儲存庫的軟體包。 python3-tkinter 是一個使用 Tk 使用 Python 3.x 編寫便攜式 GUI 應用程式的模組。然後嘗試運行此 Python 程式碼來繪製圓。
import turtle
t = turtle.Turtle()
t.circle(50)
您嘗試安裝的軟體套件sudo pip install turtle
是 HTTP 代理軟體套件。它不是適合 Turtle 圖形的包。