首页 > 解决方案 > 安装后无法运行 jupyter-book 命令

问题描述

我正在尝试使用 Jupyter-book 从我的输出中创建自动 PDF,但是在使用“pip install -U jupyter-book”命令(成功运行)安装它之后,它在我尝试时无法识别 jupyter-book运行命令:

输入:

jupyter_book create Jupyter_Book_Name

输出:

SyntaxError: invalid syntax (Temp/ipykernel_16888/3781613275.py, line 1)
  File "C:\Users\MAXIME~1.DUS\AppData\Local\Temp/ipykernel_16888/3781613275.py", line 1
    jupyter_book create Jupyter_Book_Name
                 ^
SyntaxError: invalid syntax

我已经尝试在 sys.path 中添加init jupyter_book 函数,但我得到相同的错误,并且任何命令都会出现错误。我在 Windows 10 上的 Visual Studio Code 中使用 Jupyter Notebook 在 Python 3.9.7 中工作。

在此先感谢您,任何帮助都会对我有所帮助。

标签: pythonjupyter-notebookjupyterbook

解决方案


看起来您将 shell (bash / ...) 与 Python REPL 混淆了。

您正在 Python 解释器中运行 shell 命令,有点像您尝试通过python在 Python 解释器中键入来启动 Python:

$ python   # Here I'm in bash, I run Python
Python 3.9.7 (default, Sep  3 2021, 06:18:44) 
>>> python  # Here I'm in the Python interpreter
            # typing python again...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
# Yup, calling `python` here make no sense, Python looks for a variable
# named `python` not a program named `python`, and won't find it.

所以离开 Python 解释器,找到一个 shell(取决于你的操作系统),然后再次运行命令。

哦,虽然我在这里,但可能不是:

jupyter_book create Jupyter_Book_Name

但:

jupyter-book create Jupyter_Book_Name

推荐阅读