如何修复安装Jupyter Notebook时出现的错误

21

我是Python的新手,想在Windows命令提示符窗口中安装Jupyter Notebook,使用以下命令:

pip install jupyter

但是在下载了几分钟后,会显示如下的错误信息:

  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\asd\appdata\local\programs\python\python38-32\python.exe
' 'c:\users\asd\appdata\local\programs\python\python38-32\lib\site-packages\pip\
_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\asd\Ap
pData\Local\Temp\tmpnj_hhq6y'
         cwd: C:\Users\asd\AppData\Local\Temp\pip-install-_pnki5r8\pywinpty
    Complete output (6 lines):

    Cargo, the Rust package manager, is not installed or is not on PATH.
    This package requires Rust and Cargo to compile extensions. Install it through
    the system's package manager or via https://rustup.rs/

    Checking for Rust toolchain....
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\asd\appdata\local\progr
ams\python\python38-32\python.exe' 'c:\users\asd\appdata\local\programs\python\p
ython38-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata
_for_build_wheel 'C:\Users\asd\AppData\Local\Temp\tmpnj_hhq6y' Check the logs for
full command output.
WARNING: You are using pip version 20.2.1; however, version 21.1 is available.
You should consider upgrading via the 'c:\users\asd\appdata\local\programs\pytho
n\python38-32\python.exe -m pip install --upgrade pip' command.

我只附上了错误输出的最后一部分。

如何修复此错误以成功安装Jupyter Notebook


EDIT1:我从错误消息中的链接安装了Rust软件包。然后,我再次尝试安装Jupyter Notebook,这次比之前走得更远,但仍然输出另一个错误:

Building wheels for collected packages: pywinpty
  Building wheel for pywinpty (PEP 517) ... -  WARNING: Subprocess output does
not appear to be encoded as cp1252
  WARNING: Subprocess output does not appear to be encoded as cp1252
error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\asd\appdata\local\programs\python\python38-32\python.exe'
'c:\users\asd\appdata\local\programs\python\python38-32\lib\site-packages\pip\_v
endor\pep517\_in_process.py' build_wheel 'C:\Users\asd\AppData\Local\Temp\tmpaj5
u66_y'
       cwd: C:\Users\asd\AppData\Local\Temp\pip-install-mep4ye8d\pywinpty
  Complete output (60 lines):
  Running `maturin pep517 build-wheel -i c:\users\asd\appdata\local\programs\pyt
hon\python38-32\python.exe`
     Compiling proc-macro2 v1.0.26
     Compiling unicode-xid v0.2.2
     Compiling syn v1.0.71
     Compiling winapi v0.3.9
     Compiling jobserver v0.1.22
  error: could not compile `proc-macro2`

  To learn more, run the command again with --verbose.
  warning: build failed, waiting for other jobs to finish...
  error: build failed
  dY'¥ maturin failed
    Caused by: Failed to build a native library through cargo
    Caused by: Cargo build finished with "exit code: 101": `cargo rustc --messag
e-format json --manifest-path Cargo.toml --release --lib --`
  dY\x8d1 Building a mixed python/rust project
  dY"- Found pyo3 bindings
  dY\x90\x8d Found CPython 3.8 at c:\users\asd\appdata\local\programs\python\pyt
hon38-32\python.exe
  error: linker `link.exe` not found
    |
    = note: The system cannot find the file specified. (os error 2)


  note: the msvc targets depend on the msvc linker but `link.exe` was not found


  note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option


  error: aborting due to previous error


  error: linker `link.exe` not found
    |
    = note: The system cannot find the file specified. (os error 2)


  note: the msvc targets depend on the msvc linker but `link.exe` was not found


  note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option


  error: aborting due to previous error


  error: linker `link.exe` not found
    |
    = note: The system cannot find the file specified. (os error 2)


  note: the msvc targets depend on the msvc linker but `link.exe` was not found


  note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option


  error: aborting due to previous error


  Error: command ['maturin', 'pep517', 'build-wheel', '-i', 'c:\\users\\asd\\app
data\\local\\programs\\python\\python38-32\\python.exe'] returned non-zero exit
status 1
  ----------------------------------------
  ERROR: Failed building wheel for pywinpty
Failed to build pywinpty
ERROR: Could not build wheels for pywinpty which use PEP 517 and cannot be insta
lled directly
WARNING: You are using pip version 20.2.1; however, version 21.1 is available.
You should consider upgrading via the 'c:\users\asd\appdata\local\programs\pytho
n\python38-32\python.exe -m pip install --upgrade pip' command.

你可以安装Anaconda,它会自带Jupyter。 - nobleknight
你从Jupyter文档中阅读了哪些页面?你点击过项目范围文档吗?你点击过开始使用Jupyter Notebook吗?你点击过准备安装Jupyter吗? 你点击过安装指南吗? - Mofi
或者你阅读过至少一次安装Jupyter软件页面了吗?你是否知道环境变量是如何在Windows上管理的,就像我在“X不是内部或外部命令,可执行程序或批处理文件”的原因是什么?中详细描述的那样?通常,在一个命令提示符窗口中连续安装多个Python包时会失败。请注意,“__one__”指的是“一个”。 - Mofi
1
我们不应该需要 Rust(Cargo)来安装 Python 包.. 这似乎是错误的。 - kev
@kev,我现在突然也遇到了同样的问题,这是怎么回事?我真的需要安装 Rust 吗(在哪里,如何,为什么,如何维护),才能使用 Jupyter 吗?这会导致我所有的 CI 和 Binder 安装都失败吗? - orome
7个回答

5

首先升级pip:

pip install --upgrade pip

接下来:

pip install jupyter

1
这对我也起作用了。但是我还需要通过Python运行pip:python -m pip install --upgrade pip - Martin Alexandersson

5

我在尝试在一个 32位 Python 3.8.3 执行环境上安装 notebook 失败后到达了这篇文章。据我所知,其中的依赖项 pywinpty 不支持32位执行环境(请参见下面的来源)。

我通过安装其64位版本解决了这个问题。

来源:


3

Do

pip install wheel

再试一次。这对我有用。


2
如果你收到的错误是缺少 Cargo,那么这并没有帮助。 - Abel

1

操作步骤:

  1. 检查你的Python是否为64位版本。如果不是,请到Python官网下载(例如,这里是下载3.7.9版本的链接)。点击具有“for AMD64/EM64T/x64”标签的版本进行下载。你可以下载任何你想要的版本,只是我不喜欢使用最新版。卸载你原来的Python(使用卸载文件),然后下载新的Python。别忘了在下面的“Add PATH”旁边打勾
  2. 下载Rust(内部有详细说明)–你需要一些文件。检查PATH路径,如果你需要更改,就更改它们(变量的名称和它们所在的位置都写出来了,你可以在互联网上搜索如何更改PATH变量(例如));
  3. 以管理员模式进入Windows Shell(按Win+X即可进入该界面)—— 这里是最舒适的工作地方;
  4. 进入你的python.exe(例如,我的路径是C:\Users\user\AppData\Local\Programs\Python\Python37)—— 只是为了确认;
  5. python.exe python -m pip install --upgrade pip
  6. python.exe pip install jupyter
  7. 如果出现包含缺少wheel的错误,请尝试下载它:python.exe pip install wheel

在安装过程中如果遗漏任何库,请下载并继续从你停止的步骤开始。


有没有不安装Rust的替代方法?比如说MinGW-w64之类的? - undefined

-1

-2

3
我会尽力进行翻译,以下是需要翻译的内容:我按照链接安装了,但仍然出现其他错误,如我在编辑中所附的那样。 - Jazz

-2

我在使用vscode时遇到了同样的问题。最简单的解决方案是使用conda而不是pip

conda install jupyterlab


这并没有回答问题。一旦您拥有足够的声望,您将能够评论任何帖子;相反,提供不需要询问者澄清的答案。- 来自审核 - Trenton McKinney
这并没有什么帮助。如果他们已经安装了Anaconda发行版,那么jupyterlab已经被安装了,不需要conda install jupyterlab。从OP中的路径可以清楚地看出,没有使用Anaconda。因此,这并没有回答提出的问题。另外,已经有一个被downvote的答案建议使用Anaconda,更合适的是,有一个评论也在做同样的事情。 - Trenton McKinney

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接