[英]ModuleNotFoundError: No module named '_tkinter' on Jupyter Notebook
i'm trying to put some code in jupyter notebook, and for that, i need to import tkinter.我正在尝试在 jupyter notebook 中放入一些代码,为此,我需要导入 tkinter。
I'm doing this我在做这个
from tkinter import *
And i have this error :我有这个错误:
---------------------------------------------------------------------------
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'
But when i'm doing in local python3 script.py
everything is working.但是当我在本地
python3 script.py
执行时,一切正常。 And i have tkinter in my pc.我的电脑里有 tkinter。 I'm using Fedora.
我正在使用 Fedora。 I've already tried to reinstall but nothing is working.
我已经尝试重新安装,但没有任何效果。 Anyone have a clue ?
有人有线索吗?
The anwser of furas was correct. furas 的回答是正确的。 My problem was I had two python3 and jupyter notebook didn't have the good version.
我的问题是我有两个 python3 和 jupyter notebook 没有好的版本。
Basically, to fix this problem :基本上,要解决这个问题:
$which python
-> alias python='/usr/bin/python3.7'
/usr/bin/python3.7
Now i know the path of the python with my tkinter.现在我用我的 tkinter 知道了 python 的路径。 I just need to find the kernel of my jupyter notebook and update the kernel.json with the path of my actual 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
When i'm opening my kernel.json i have当我打开我的 kernel.json 我有
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python",
}
I just need to add the path of my python3我只需要添加我的python3的路径
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python",
"env": {
"PYTHONPATH": "/usr/bin/"
}
}
And now, i can use tkinter (or another) in jupyter notebook现在,我可以在 jupyter notebook 中使用 tkinter(或其他)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.