![](/img/trans.png)
[英]Jupyter Notebook ModuleNotFoundError --> No module named 'sql'
[英]ModuleNotFoundError: No module named '_tkinter' on Jupyter Notebook
我正在嘗試在 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(或其他)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.