gpt4 book ai didi

python-3.x - python3 tkinter ubuntu trusty 在虚拟环境下不起作用

转载 作者:IT老高 更新时间:2023-10-28 21:26:56 31 4
gpt4 key购买 nike

我在一个 ubuntu 可信赖的 docker 容器上安装了 python3-tk。(apt-get install python3-tk)

> python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> import tkinter as tk
>>>

到目前为止一切顺利。但是,由于不同的原因,我需要在同一个容器中运行加载的 python3 virtualenv。当我激活虚拟环境时:

(env_py34)root@8a7953c24d4f:/home# python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter as tk
Traceback (most recent call last):
File "/usr/lib/python3.4/tkinter/__init__.py", line 39, in <module>
import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/tkinter/__init__.py", line 41, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
>>>

python 的版本是相同的。为什么虚拟环境没有从python3安装继承python3-tk?如何在虚拟环境中安装 python3-tk?

最佳答案

所以从错误信息来看,python3-tk 包丢失了。

raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package

您是否尝试安装它?例如,在 ubuntu 中

sudo apt-get install python3-tk

关于python-3.x - python3 tkinter ubuntu trusty 在虚拟环境下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34890383/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com