Python 在 Windows 上通过命令行运行 jupyter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41034866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:22:59  来源:igfitidea点击:

Running jupyter via command line on Windows

pythonjupyter-notebookjupyter

提问by eleijonmarck

I have installed Jupyter on Windows 10, python 3.x via

我已经在 Windows 10、python 3.x 上安装了 Jupyter

$ pip install jupyter

The installation for works fine, even though I did restart the terminal.

安装工作正常,即使我确实重新启动了终端。

But trying to run

但是想跑

$ jupyter notebook

'jupyter' is not recognized as an internal or external command, operable program or batch file.

'jupyter' 不是内部或外部命令,也不是可运行的程序或批处理文件。

How and where do I find the executable for Jupyter?

我如何以及在哪里找到 Jupyter 的可执行文件?

回答by user6094431

If you are absolutely sure that your python library path is in your system variables (and you can find that path when you pip install jupyter, you just have to read a bit) and you still experience "command not found or recognized" errors in windows, you can try:

如果您绝对确定您的 python 库路径在您的系统变量中(并且您可以在 pip install jupyter 时找到该路径,您只需阅读一点)并且您仍然在 Windows 中遇到“找不到或无法识别命令”错误, 你可以试试:

python -m notebook

For my windows at least (Windows 10 Pro), having the python -m is the only way I can run my python packages from command line without running into some sort of error

至少对于我的 Windows(Windows 10 Pro),拥有 python -m 是我可以从命令行运行我的 python 包而不会遇到某种错误的唯一方法

Fatal error in launcher: Unable to create process using ' "

启动器中的致命错误:无法使用“”创建进程

or

或者

Errno 'THIS_PROGRAM' not found

找不到错误“THIS_PROGRAM”

回答by Johnn Smith

I had the same problem, but

我有同样的问题,但是

py -m notebook

worked for me.

为我工作。

回答by eleijonmarck

Please try this command; first

请试试这个命令;第一的

$ py -m notebook

Otherwise

除此以外

$ python -m pip install jupyter --user
$ jupyter notebook

If this does not work.

如果这不起作用。

pip does not add jupyter directly to path for local.

pip 不会将 jupyter 直接添加到本地路径。

The output from

输出来自

$ which python
/c/Users/<username>/AppData/Local/Programs/Python/Python35-32/python

After some digging I found a executable for jupyter in the folder:

经过一番挖掘,我在文件夹中找到了 jupyter 的可执行文件:

C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts\jupyter.exe

Difference between local and roaming folder

本地文件夹和漫游文件夹的区别

So if you want to be able to execute a program via command line, you need to add it into the %PATH variable. Here is a powershell script to do it. BE SURE TO ADD THE ";" before adding the new path.

因此,如果您希望能够通过命令行执行程序,则需要将其添加到 %PATH 变量中。这是一个powershell脚本来做到这一点。请务必添加“;” 在添加新路径之前。

$ [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts", [EnvironmentVariableTarget]::User)

Update:

更新:

if you are using python3, switch out pythonwith python3but I encourage you to use pyenvinstead :)

如果您正在使用python3,请换python用,python3但我鼓励您pyenv改用 :)

回答by John P

I got Jupyter notebook running in Windows 10. I found the easiest way to accomplish this task without relying upon a distro like Anaconda was to use Cygwin.

我让 Jupyter 笔记本在 Windows 10 中运行。我发现在不依赖 Anaconda 等发行版的情况下完成此任务的最简单方法是使用 Cygwin。

In Cygwin install python2, python2-devel, python2-numpy, python2-pip, tcl, tcl-devel, (I have included a image below of all packages I installed) and any other python packages you want that are available. This is by far the easiest option.

在 Cygwin 中,安装 python2、python2-devel、python2-numpy、python2-pip、tcl、tcl-devel(我在下面包含了我安装的所有软件包的图像)以及您想要的任何其他可用的 Python 软件包。这是迄今为止最简单的选择。

Then run this command to just install jupyter notebook:

然后运行这个命令来安装 jupyter notebook:

python -m pip install jupyter

Below is the actual commands I ran to add more libraries just in case others need this list too:

以下是我运行以添加更多库的实际命令,以防其他人也需要此列表:

python -m pip install scipy

python -m pip install scikit-learn

python -m pip install sklearn

python -m pip install pandas

python -m pip install matplotlib

python -m pip install jupyter

If any of the above commands fail do not worry the solution is pretty simple most of the time. What you do is look at the build failure for whatever missing package / library.

如果上述任何命令失败,请不要担心,大多数情况下解决方案非常简单。您所做的是查看任何缺少的包/库的构建失败。

Say it is showing a missing pyzmq then close Cygwin, re-open the installer, get to the package list screen, show "full" for all, then search for the name like zmq and install those libraries and re-try the above commands.

假设它显示缺少 pyzmq,然后关闭 Cygwin,重新打开安装程序,进入包列表屏幕,显示“完整”,然后搜索 zmq 之类的名称并安装这些库,然后重新尝试上述命令。

Using this approach it was fairly simple to eventually work through all the missing dependencies successfully.

使用这种方法,最终成功处理所有缺失的依赖项是相当简单的。

Cygwin package list

Cygwin 软件包列表

Once everything is installed then run in Cygwin goto the folder you want to be the "root" for the notebook ui tree and type:

安装完所有内容后,在 Cygwin 中运行,转到您想要成为 notebook ui 树的“根”的文件夹并键入:

jupyter notebook

This will start up the notebook and show some output like below:

这将启动笔记本并显示如下输出:

$ jupyter notebook
[I 19:05:30.459 NotebookApp] Serving notebooks from local directory: 
[I 19:05:30.459 NotebookApp] 0 active kernels
[I 19:05:30.459 NotebookApp] The Jupyter Notebook is running at: 
[I 19:05:30.459 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Copy/paste this URL into your browser when you connect for the first time, to login with a token:

http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

回答by AZBlue

If you are using the Anaconda distribution, make sure when installing it that you check the "Change PATH" option.

如果您使用的是 Anaconda 发行版,请确保在安装时选中“更改路径”选项。

回答by Parash

You can add the following to your path

您可以将以下内容添加到您的路径中

C:[Python Installation path]\Scripts

C:[Python 安装路径]\Scripts

e.g. C:\Python27\Scripts

例如 C:\Python27\Scripts

It will start working for jupyter and every other pip install you will do here on.

它将开始为 jupyter 以及您将在此处执行的所有其他 pip 安装工作。

回答by Mohammed Fali

I added

我加了

 c:\users\[user]\appdata\roaming\python\python37\site-packages

to the path and it worked.

到路径并且它起作用了。

回答by iliketocode

Problem for me was that I was running the jupytercommand from the wrong directory.

对我来说问题是我jupyter从错误的目录运行命令。

Once I navigated to the path containing the script, everything worked.

一旦我导航到包含脚本的路径,一切正常。

Path- C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts

小路- C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts

回答by Maros

Here is how I resolved stated issue, hope it helps:

以下是我解决所述问题的方法,希望对您有所帮助:

  1. install python 3.7 using official website for python, while installing include installing PATH by checking it's box

  2. after that open cmd (be sure to open it after step 1) and write: pip install jupyter ENTER

  3. now you should be able to open jupyter notebook by using command: jupyter notebook

  1. 使用官方网站为 python 安装 python 3.7,同时安装包括通过选中它的框来安装 PATH

  2. 之后打开cmd(一定要在第1步之后打开它)并写:pip install jupyter ENTER

  3. 现在您应该可以使用以下命令打开 jupyter notebook:jupyter notebook

Seems simple, but it may as well help.

看起来很简单,但它也可能有所帮助。

回答by manar odeh

first you should make sure that you are put your python path in your system variables .. Then try run this

首先你应该确保你把你的python路径放在你的系统变量中..然后尝试运行这个

    python -m pip install jupyter --user

and then run this

然后运行这个

    py -m notebook or  jupyter notebook