200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 更新PYthon3.8 以及Python may not be configured for TK解决

更新PYthon3.8 以及Python may not be configured for TK解决

时间:2021-07-11 01:17:55

相关推荐

更新PYthon3.8 以及Python may not be configured for TK解决

最近开始学习Python,于是安装了ubuntu18.04LTS 并构建系统,本人小白级别,全靠网上大师指点。

在此多谢。

ubuntu18.04LTS自带的python为3.6版本

于是进行了更新3.8版本,更新方法参考:

/Linux/-11/161448.htm

更新完之后正常使用如下:

~$ python3.8Python 3.8.1 (default, Feb 23 , 13:19:04) [GCC 7.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>>

查看python3.8安装位置

~$ which python3.8/usr/local/bin/python3.8

我这里没有该python3的指向,故默认python3还是原来的版本

$ python3Python 3.6.9 (default, Nov 7 , 10:44:02) [GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>>

修改指向可参考:

/u014775723/article/details/85213793

/nightelf00/article/details/89408658

改默认python3指向,终端会打不开,需要修改gnome-terminal的第一行

默认如下:

sudo gedit /usr/bin/gnome-terminal

#!/usr/bin/python3import stringimport subprocessimport sysimport random

查看python3的指向

$ ls -l /usr/bin | grep pythonlrwxrwxrwx 1 root root26 3月 27 dh_pypy -> ../share/dh-python/dh_pypylrwxrwxrwx 1 root root29 3月 27 dh_python3 -> ../share/dh-python/dh_python3lrwxrwxrwx 1 root root23 2月 23 12:16 pdb3.6 -> ../lib/python3.6/pdb.pylrwxrwxrwx 1 root root31 2月 23 12:16 py3versions -> ../share/python3/py3versions.pylrwxrwxrwx 1 root root26 3月 27 pybuild -> ../share/dh-python/pybuildlrwxrwxrwx 1 root root 9 2月 23 12:16 python3 -> python3.6 -rwxr-xr-x 1 root root4526456 11月 7 18:44 python3.6lrwxrwxrwx 1 root root33 11月 7 18:44 python3.6-config -> x86_64-linux-gnu-python3.6-config-rwxr-xr-x 1 root root4526456 11月 7 18:44 python3.6mlrwxrwxrwx 1 root root34 11月 7 18:44 python3.6m-config -> x86_64-linux-gnu-python3.6m-configlrwxrwxrwx 1 root root16 10月 25 python3-config -> python3.6-configlrwxrwxrwx 1 root root10 2月 23 12:16 python3m -> python3.6mlrwxrwxrwx 1 root root17 10月 25 python3m-config -> python3.6m-configlrwxrwxrwx 1 root root34 11月 7 18:44 x86_64-linux-gnu-python3.6-config -> x86_64-linux-gnu-python3.6m-config-rwxr-xr-x 1 root root 3283 11月 7 18:44 x86_64-linux-gnu-python3.6m-configlrwxrwxrwx 1 root root33 10月 25 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.6-configlrwxrwxrwx 1 root root34 10月 25 x86_64-linux-gnu-python3m-config -> x86_64-linux-gnu-python3.6m-config

因为python3 -> python3.6 ,所以如果将python3的指向改为3.8后,需要为gnome-terminal修改第一行:

#!/usr/bin/python3.6import stringimport subprocessimport sysimport random

到此正常使用Python3.8 安装VScode ,开始学习。

××××××××××××××××××××××××××××××××××××××××

学习turtle时候出现问题

If this fails your Python may not be configured for Tk

查询需要安装TK以及dev

安装tk>> sudo apt install python3-tk (Ubuntu)>> yum install python3-tk (Centos)安装tk开发类库:>> sudo apt install tk-dev (Ubuntu)>> yum install tk-devel (Centos)

安装之后,python3.6可以正常使用

Python 3.6.9 (default, Nov 7 , 10:44:02) [GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import tkinter>>>

但是python3.8依然报错

$ python3.8Python 3.8.1 (default, Feb 23 , 13:19:04) [GCC 7.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import tkinterTraceback (most recent call last):File "<stdin>", line 1, in <module>File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in <module>import _tkinter # If this fails your Python may not be configured for TkModuleNotFoundError: No module named '_tkinter'>>> exit()

查找资料,对比自己的安装,发现,TK包已经安装,但是3.8无法调用

已经安装:

~$ sudo apt install python3-tk [sudo] wangnan 的密码: 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 python3-tk 已经是最新版 (3.6.9-1~18.04)。升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

发现在python3.8 import tkinter 的时去找3.8的库文件/usr/local/lib/python3.8/

而python3.8的 tkinter so文件实际上被安装到了 /usr/lib/python3.8/lib-dynload

将文件复制到/usr/local/lib/python3.8/lib-dynload/下面

/usr/lib/python3.8/lib-dynload$ sudo cp _tkinter.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.8/lib-dynload/

之后可以正常import tkinter

~$ python3.8Python 3.8.1 (default, Feb 23 , 13:19:04) [GCC 7.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import tkinter>>>

参考:

/article/54153.htm

/jeryjeryjery/article/details/78865362

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。