bzs*_*sol 6 python tkinter python-poetry
  File "project.py", line 5, in <module>
    from tkinter.filedialog import askopenfilenames
ModuleNotFoundError: No module named 'tkinter'
当我想用诗歌运行 python project.py 运行我的项目时,这种情况总是会发生,但如果我本机运行它就可以完美地工作。所以我猜问题是将 Tkinter 添加到 .toml 文件中,但是当我将 tk 添加到依赖项时,它无法正常工作。我应该怎么办?
小智 0
我也有这个问题,但正如 @furas 提到的,tkinter 默认情况下没有安装在某些 ubuntu serverion 上(我运行(在 windows 中)ubuntu 22.04 LTS),带有 Poetry(版本 1.6.1)和 python 3.10
所以我必须通过 apt-get 安装 tkinter: sudo apt-get install python3-tk
现在 tkinter 已安装,但它仍然无法添加到 .tomel,但如果我没有添加它并使用“poetry run python project.py”运行项目,它运行时不会出现任何问题。它似乎与所有标准 Python 库都是一样的。我的 .toml 是:
[tool.poetry]
name = "test-gui"
version = "0.1.0"
description = ""
authors = ["JonTheBaboon"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
pillow = "^10.1.0"
tk = "^0.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
你提到了 tk,如果你运行“poetry add tk”,你将得到另一个包“TensorKit”,请参阅诗歌.lock 文件:
name = "tk"
version = "0.1.0"
description = "TensorKit is a deep learning helper between Python and C++."
optional = false
python-versions = "*"
| 归档时间: | 
 | 
| 查看次数: | 2019 次 | 
| 最近记录: |