Python版本3.10.6无法在Visual studio代码上运行jupyter笔记本



我使用的是我的conda环境,它有3.10.6 python版本,但当我尝试在Visual studio代码上运行jupyter笔记本单元时,它会产生这个错误

Failed to start the Kernel. 
NameError: name 'f' is not defined. 
View Jupyter log for further details.

这个问题只发生在3.10.6版本,但在3.9版本上,Visual studio代码仍然可以正常工作

这是我的conda列表

#
# Name                    Version                   Build  Channel
asttokens                 2.0.8              pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2022.9.24            h5b45459_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
debugpy                   1.6.3           py310h8a704f9_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
executing                 1.1.1              pyhd8ed1ab_0    conda-forge
ipykernel                 6.9.1           py310haa95532_0    anaconda
ipython                   8.5.0              pyh08f2357_1    conda-forge
jedi                      0.18.1             pyhd8ed1ab_2    conda-forge
jupyter_client            7.4.4              pyhd8ed1ab_0    conda-forge
jupyter_core              4.11.1          py310h5588dad_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libsodium                 1.0.18               h8d14728_1    conda-forge
libsqlite                 3.39.4               hcfcfb64_0    conda-forge
libzlib                   1.2.13               hcfcfb64_4    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
openssl                   3.0.5                hcfcfb64_2    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       22.3               pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.31             pyha770c72_0    conda-forge
psutil                    5.9.3           py310h8d17308_1    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.13.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
python                    3.10.6          hcf16a7b_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.10                    2_cp310    conda-forge
pywin32                   303             py310h8d17308_1    conda-forge
pyzmq                     24.0.1          py310hcd737a0_0    conda-forge
setuptools                65.5.0             pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
stack_data                0.5.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
tornado                   6.2             py310h8d17308_1    conda-forge
traitlets                 5.5.0              pyhd8ed1ab_0    conda-forge
tzdata                    2022e                h191b570_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.3                 h3d8a991_9    conda-forge
vs2015_runtime            14.32.31332          h1d6e394_9    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
zeromq                    4.3.4                h0e60522_1    conda-forge

这是我的jupyter日志

Visual Studio Code (1.72.2, undefined, desktop)
Jupyter Extension Version: 2022.10.1103011060.
Python Extension Version: 2022.16.1.
No workspace folder opened.
info 02:11:44.347: ZMQ install verified.
User belongs to experiment group 'jupyterTestcf'
User belongs to experiment group 'jupyterEnhancedDataViewer'
info 02:11:44.561: LSP Notebooks experiment is enabled
info 02:11:44.584: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:45.488: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:45.488: Find preferred kernel for c:update-auto-exercisefiltering.ipynb with metadata {"kernelspec":{"display_name":"python_3.10","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749"}}} & preferred interpreter <undefined>
info 02:11:45.490: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:45.490: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:45.490: Find preferred kernel for c:update-auto-exercisefiltering.ipynb with metadata {"kernelspec":{"display_name":"python_3.10","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749"}}} & preferred interpreter <undefined>
info 02:11:45.491: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:47.547: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:47.547: Find preferred kernel for c:update-auto-exercisefiltering.ipynb with metadata {"kernelspec":{"display_name":"python_3.10","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749"}}} & preferred interpreter <undefined>
info 02:11:47.548: Preferred Remote kernel for c:update-auto-exercisefiltering.ipynb is undefined
info 02:11:47.548: Preferred kernel .jvsc74a57bd0b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749.c:Usersearthanaconda3envspython_3.10python.exe.c:Usersearthanaconda3envspython_3.10python.exe.-m#ipykernel_launcher is exact match or top match for non python kernels, (false, undefined, true, false)
info 02:11:47.549: PreferredConnection: .jvsc74a57bd0b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749.c:Usersearthanaconda3envspython_3.10python.exe.c:Usersearthanaconda3envspython_3.10python.exe.-m#ipykernel_launcher found for NotebookDocument: c:update-auto-exercisefiltering.ipynb
error 02:11:49.277: Live Notebook not available for c:update-auto-exercisefiltering.ipynb
info 02:11:50.227: Got env vars ourselves faster c:Usersearthanaconda3envspython_3.10python.exe with env var count 75 in 2677ms
info 02:11:50.232: Process Execution: > ~anaconda3envspython_3.10python.exe -m pip list
> ~anaconda3envspython_3.10python.exe -m pip list
info 02:11:50.304: Got env vars with python c:Usersearthanaconda3envspython_3.10python.exe, with env var count 77 and custom env var count 0 in 2754ms
info 02:12:05.695: Starting Jupyter Session startUsingPythonInterpreter, .jvsc74a57bd0b74fcc8dd08447e1fbd53a0778a82215155d17559b2612b639fc7e8ffed26749.c:Usersearthanaconda3envspython_3.10python.exe.c:Usersearthanaconda3envspython_3.10python.exe.-m#ipykernel_launcher (Python Path: c:Usersearthanaconda3envspython_3.10python.exe, EnvType: Conda, EnvName: 'python_3.10', Version: 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:29:51) [MSC v.1929 64 bit (AMD64)]) for 'c:update-auto-exercisefiltering.ipynb' (disableUI=false)
info 02:12:05.696: Computing working directory for resource 'c:update-auto-exercisefiltering.ipynb'
info 02:12:05.698: Got env vars ourselves faster c:Usersearthanaconda3envspython_3.10python.exe with env var count 75 in 1ms
info 02:12:05.699: Got env vars with python c:Usersearthanaconda3envspython_3.10python.exe, with env var count 77 and custom env var count 0 in 2ms
info 02:12:05.703: Process Execution: > ~anaconda3envspython_3.10python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~anaconda3envspython_3.10python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 02:12:05.739: Got env vars ourselves faster c:Usersearthanaconda3envspython_3.10python.exe with env var count 75 in 1ms
info 02:12:05.739: Got env vars ourselves faster c:Usersearthanaconda3envspython_3.10python.exe with env var count 75 in 0ms
info 02:12:05.740: Got env vars with python c:Usersearthanaconda3envspython_3.10python.exe, with env var count 77 and custom env var count 0 in 2ms
info 02:12:05.740: Got env vars with python c:Usersearthanaconda3envspython_3.10python.exe, with env var count 77 and custom env var count 0 in 1ms
info 02:12:05.743: Got env vars ourselves faster c:Usersearthanaconda3envspython_3.10python.exe with env var count 75 in 0ms
info 02:12:05.744: Got env vars with python c:Usersearthanaconda3envspython_3.10python.exe, with env var count 77 and custom env var count 0 in 1ms
info 02:12:05.748: Process Execution: > ~anaconda3envspython_3.10python.exe ~.vscodeextensionsms-toolsai.jupyter-2022.10.1103011060pythonFilesvscode_datascience_helperskernel_interrupt_daemon.py --ppid 23332
> ~anaconda3envspython_3.10python.exe ~.vscodeextensionsms-toolsai.jupyter-2022.10.1103011060pythonFilesvscode_datascience_helperskernel_interrupt_daemon.py --ppid 23332
info 02:12:05.748: Process Execution: cwd: ~.vscodeextensionsms-toolsai.jupyter-2022.10.1103011060pythonFilesvscode_datascience_helpers
cwd: ~.vscodeextensionsms-toolsai.jupyter-2022.10.1103011060pythonFilesvscode_datascience_helpers
warn 02:12:05.869: Error output in interrupt daemon response 23332
info 02:12:05.874: Process Execution: > ~anaconda3envspython_3.10python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"b4c26c91-4956-43b0-b135-21c786f2e2d8" --shell=9002 --transport="tcp" --iopub=9004 --f=c:UsersearthAppDataRoamingjupyterruntimekernel-v2-233323lVaEdmBZNNU.json
> ~anaconda3envspython_3.10python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"b4c26c91-4956-43b0-b135-21c786f2e2d8" --shell=9002 --transport="tcp" --iopub=9004 --f=c:UsersearthAppDataRoamingjupyterruntimekernel-v2-233323lVaEdmBZNNU.json
info 02:12:05.874: Process Execution: cwd: c:update-auto-exercise
cwd: c:update-auto-exercise
info 02:12:06.073: ipykernel version & path 6.9.1, ~anaconda3envspython_3.10libsite-packagesipykernel__init__.py for c:Usersearthanaconda3envspython_3.10python.exe
warn 02:12:07.058: StdErr from Kernel Process c:Usersearthanaconda3envspython_3.10libsite-packagestraitletstraitlets.py:2412: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
warn(
warn 02:12:07.058: StdErr from Kernel Process c:Usersearthanaconda3envspython_3.10libsite-packagestraitletstraitlets.py:2366: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'b4c26c91-4956-43b0-b135-21c786f2e2d8' instead of 'b"b4c26c91-4956-43b0-b135-21c786f2e2d8"'.
warn(
info 02:12:07.125: Kernel Output: To connect another client to this kernel, use: --existing c:UsersearthAppDataRoamingjupyterruntimekernel-v2-233323lVaEdmBZNNU.json
warn 02:12:07.125: StdErr from Kernel Process Traceback (most recent call last):
File "c:Usersearthanaconda3envspython_3.10librunpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:Usersearthanaconda3envspython_3.10librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:Usersearthanaconda3envspython_3.10libsite-packagesipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "c:Usersearthanaconda3envspython_3.10libsite-packagestraitletsconfigapplication.py", line 981, in launch_instance
app.initialize(argv)
File "c:Usersearthanaconda3envspython_3.10libsite-packagestraitletsconfigapplication.py", line 110, in inner
return method(app, *args, **kwargs)
File "c:Usersearthanaconda3envspython_3.10libsite-packagesipykernelkernelapp.py", line 647, in initialize
self.init_kernel()
File "c:Usersearthanaconda3envspython_3.10libsite-packagesipykernelkernelapp.py", line 499, in init_kernel
kernel = kernel_factory(parent=self, session=self.session,
File "c:Usersearthanaconda3envspython_3.10libsite-packagestraitletsconfigconfigurable.py", line 551, in instance
inst = cls(*args, **kwargs)
File "c:Usersearthanaconda3envspython_3.10libsite-packagesipykernelipkernel.py", line 90, in __init__
self.shell = self.shell_class.instance(parent=self,
File "c:Usersearthanaconda3envspython_3.10libsite-packagestraitletsconfigconfigurable.py", line 551, in instance
inst = cls(*args, **kwargs)
File "c:Usersearthanaconda3envspython_3.10libsite-packagesIPythoncoreinteractiveshell.py", line 562, in __init__
self.init_history()
File "c:Usersearthanaconda3envspython_3.10libsite-packagesIPythoncoreinteractiveshell.py", line 1749, in init_history
self.history_manager = HistoryManager(shell=self, parent=self)
File "c:Usersearthanaconda3envspython_3.10libsite-packagesIPythoncorehistory.py", line 538, in __init__
super(HistoryManager, self).__init__(shell=shell, config=config,
File "c:Usersearthanaconda3envspython_3.10libsite-packagesIPythoncorehistory.py", line 218, in __init__
self.init_db()
File "c:Usersearthanaconda3envspython_3.10libsite-packagesdecorator.py", line 232, in fun
return caller(f, *(extras + args), **kw)
NameError: name 'f' is not defined

我需要用3.10.6 python在Visual studio代码上运行jupyter笔记本,有什么方法可以解决这个问题吗?

在cmd中使用以下命令检查内核规范:

jupyter kernelspec list

它将向您显示可用的内核。

对我来说,我可以得到:

C:UsersAdmin>jupyter kernelspec list
Available kernels:
python3    c:UsersAdminAppDataLocalProgramsPythonPython310sharejupyterkernelspython3

打开该目录中的kernel.json文件,并在argv中指定您想要的python的路径。

您也可以尝试在cmd中更新jupyter,而不是anaconda:

pip install -U jupyter

最新更新