问题1
pip3 install turtle 安装报错
安装turtle显示语法错误
解决
下载turtle源码:
https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
打开下载好的turtle压缩文件,修改setup.py 文件的第40行
except ValueError, ve : 改为----> except (ValueError, ve ):
即源码上增加了括号,python2的语法格式是没有括号的,但是python3没有括号就会报错,就像print函数
pip install -e turtle-0.0.2
turtle-0.0.2为下载文件路径及名称
you01@you01-BANFF12:~$ pip install -e /home/turtle-0.0.2
......
Successfully installed Automat-20.2.0 PyHamcrest-1.10.1 PyYAML-5.3.1 Twisted-20.3.0 attrs-19.3.0 constantly-15.1.0 hyperlink-19.0.0 idna-2.9 incremental-17.5.0 setuptools-44.1.1 six-1.15.0 turtle zope.interface-5.1.0
安装好后重新进入python3 出现需要导入tkinter模块,还是无法正常运行
>>> import turtle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/turtle.py", line 107, in <module>
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
问题2
导入tkinter模块后,运行还是出现No module named _tkinter, please install the python-tk package ubuntu运行tkinter错误
解决
首先
sudo apt-get update(如果不更新很有可能找不到tkinter),
然后
sudo apt-get install python3-tk
成功
>>> import turtle
>>>
网友评论