python - ModuleNotFoundError:Jupyter Notebook 上没有名为“_tkinter”的模块
问题描述
我正在尝试将一些代码放在 jupyter notebook 中,为此,我需要导入 tkinter。
我正在做这个
from tkinter import *
我有这个错误:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-67079ccbcb8c> in <module>
1 import nltk
----> 2 from tkinter import *
3 from nltk.chat.util import Chat, reflections
4 from nltk.corpus import wordnet as wn
5 import string
/usr/local/lib/python3.7/tkinter/__init__.py in <module>
34 import sys
35
---> 36 import _tkinter # If this fails your Python may not be configured for Tk
37 TclError = _tkinter.TclError
38 from tkinter.constants import *
ModuleNotFoundError: No module named '_tkinter'
但是当我在本地做的时候,python3 script.py
一切都正常。我的电脑里有 tkinter。我正在使用 Fedora。我已经尝试重新安装,但没有任何效果。有人有线索吗?
解决方案
furas的答案是正确的。我的问题是我有两个 python3 和 jupyter notebook 没有好的版本。
基本上,要解决这个问题:
$which python
-> alias python='/usr/bin/python3.7'
/usr/bin/python3.7
现在我用我的 tkinter 知道了 python 的路径。我只需要找到我的 jupyter notebook 的内核并用我的实际 python 的路径更新 kernel.json
$jupyter kernelspec list
-> Available kernels:
python3 /home/Natko/.local/share/jupyter/kernels/python3
$nano /home/Natko/.local/share/jupyter/kernels/python3/kernel.json
当我打开我的 kernel.json 我有
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python",
}
我只需要添加我的python3的路径
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python",
"env": {
"PYTHONPATH": "/usr/bin/"
}
}
现在,我可以在 jupyter notebook 中使用 tkinter(或其他)
推荐阅读
- statistics - SAS 中的列分析
- non-linear-regression - 具有缩放 t 分布的 GAMM:为什么我的残差和拟合值不能与观察值相加?
- javascript - JS onEventListener 一起运行两个独立的函数
- python - 在 Spyder 中安装 Pandas
- c++ - C++/libpng - fclose() 在调用 png_write_png() 后“触发断点”
- javascript - 没有重载将此调用与样式化组件匹配
- microsoft-graph-api - ngrok 被 Fortinet FortiGuard 阻止
- reactjs - 在 S3 中删除旧的反应构建文件
- c++ - VSCode:工作区文件夹的子目录中的头文件看不到其他目录中的头文件
- java - 使用 javaFx 进行春季启动