无法在 VSCode 中运行 Jupyter Notebook - Vanilla Python、Windows 10 [英] Can't run Jupyter Notebook in VSCode - Vanilla Python, Windows 10

查看:150
本文介绍了无法在 VSCode 中运行 Jupyter Notebook - Vanilla Python、Windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 10 计算机上安装了现有的香草 Python,我不想重新安装 Anaconda.

I have an existing vanilla Python installed on my Windows 10 computer and I do not want to reinstall Anaconda.

在 vscode 中尝试从 ipynb 文件运行代码时,出现以下错误:

When trying to run code from ipynb file in vscode, I get the following error:

Error: Jupyter cannot be started. Error attempting to locate jupyter:
at A.startServer (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:786120)
at async A.ensureServerAndNotebookImpl (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785575)
at async A.ensureServerAndNotebook (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785376)
at async A.submitCode (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:782328)
at async A.reexecuteCell (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:75:879318)

还有来自 VSCode 的以下错误:

Also with the following error from VSCode:

以下是我尝试过的一些方法:

Below are some of the things I have tried:

检查是否正确安装了 VSCode 扩展

Jupyter"不推荐使用扩展.我有Python"安装了来自 Microsoft 的插件,其中包含 Jupiter Notebook 支持.

"Jupyter" extensions is deprecated. I had the "Python" plugin from Microsoft installed which contained Jupiter Notebook support.

Jupyter 安装正确

我尝试重新安装 jupyter:

I tried reinstalling jupyter:

> python -m pip install --upgrade pip
> pip install jupyter
> pip install notebook

尝试在终端/命令行上运行 Jupyter

> jupyter notebook    //didn't work
jupyter : The term 'jupyter' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or   
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ jupyter
+ ~~~~~~~
+ CategoryInfo          : ObjectNotFound: (jupyter:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

这给出了一个错误,无法找到 jupyter 可执行文件.根据这篇文章,我尝试了以下操作,结果奏效了:>

This gave an error not able to find jupyter executable. According to this post I tried the following and it worked:

> python -m notebook

检查是否指向正确的解释器

根据这篇文章,我尝试了:

  1. 按 Command+Shift+P 打开一个新的命令面板
  2. 输入 >Python:选择 Intepreter 以启动 jupyter notebook 服务器

但我的电脑上只安装了一个版本的 Python,这样做并没有什么不同.

But I only had one version of Python installed on my computer, and doing this didn't make a difference.

检查路径

这篇文章 但由于正确引用了 python 目录并且 python 从命令行工作,我做到了不再进一步调查.

There was this comment about PYTHONPATH in this post but since the python directory is correctly referenced and python works from the command line, I did not investigate it further.

需要注意的是 pip 安装到我的 "C:/Users/[username]/appdata/Roaming/Python-38/" 文件夹,而我的Python 安装在 "C:\Program Files\Python38-32\" 中.

One thing to note is pip installs to my "C:/Users/[username]/appdata/Roaming/Python-38/" folder while my Python is installed in "C:\Program Files\Python38-32\".

推荐答案

如果您遇到类似问题,请尝试上述问题中提到的步骤.

If you are having similar issues, please try the above steps mentioned in the question.

阅读这篇文章后,我意识到我也必须映射用 pip 安装的脚本,即使它在我的漫游目录中.https://discuss.python.org/t/windows-appdata-roaming-vs-local/2682.一个让我花费了很多小时的困惑.

After reading this article I realised that I had to map the scripts installed with pip as well, even if it is in my roaming directory. https://discuss.python.org/t/windows-appdata-roaming-vs-local/2682. A confusion that costed me so many hours.

以下是添加变量的步骤:

Here are the steps to add the variable:

  1. 转到环境变量(如果您不知道如何操作,这里有一些说明:https://www.techjunkie.com/environment-variables-windows-10/)
  2. 在[username] 的用户变量"部分,编辑PATH"变量.(它不能是系统变量部分,因为只有您才能访问自己的漫游文件夹)
  3. 添加C:\Users[用户名]\AppData\Roaming\Python\Python38\Scripts"(或 pip 将脚本安装到 PATH 变量的位置.

最后重新启动 VSCode,以便为 VSCode 更新新的环境变量.现在运行 ipynb 文件中的脚本,它应该可以工作.它也可能会抱怨它需要其他模块,在这种情况下,您可以使用pip"来安装它.

Finally restart VSCode for the new environmental variable to be updated for VSCode. Now run the scripts in the ipynb file and it should work. It may also complain that it needs other modules, in which case you can use 'pip' to install it.

注意:如果您不受计算机上现有 Python 版本的限制并且不想安装更多版本,您也可以使用 Python Anaconda Distribution.https://www.anaconda.com/distribution/

NB: if you are not constrained by having an existing python version on your computer and not wanting to install more, you can also use the Python Anaconda Distribution. https://www.anaconda.com/distribution/

注意:如果您希望 jupyter note 为使用您计算机的所有用户工作,您需要配置 pip 将安装下载到不在您的C:\Users[username]"文件夹中的目录中,并添加一个系统可变的.

NB: if you want jupyter note to work for all users using your computer, you need to configure pip to download installs to a directory that is not in your "C:\Users[username]" folder, and add a System variable to it.

这篇关于无法在 VSCode 中运行 Jupyter Notebook - Vanilla Python、Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆