【问题标题】:using bash commands in jupyter notebook在 jupyter notebook 中使用 bash 命令
【发布时间】:2018-01-31 10:28:20
【问题描述】:

我从未将 bash 与 jupyter notebook 一起使用。对于某些项目,我需要将 bash 与 python 一起使用,但它给了我错误。我也安装了 bash 内核。

PATH="/Downloads/dogscats/"
!ls {PATH}

'ls' 未被识别为内部或外部命令, 可运行的程序或批处理文件。

【问题讨论】:

  • 你使用的是什么操作系统?
  • {PATH} 并不是一个真正有效的 Bash 表达式。也许您的意思是${PATH}(但是大括号并不是真正有用或必要的)? (不过对 Jupyter 不太熟悉。)
  • 使用windows 8.1

标签: python jupyter-notebook


【解决方案1】:

只要从符合 bash 的命令行(例如 Git Bash (MingW64))启动 Jupyter,就可以在 Jupyter Notebook 中使用 bash 命令,即使在 Windows 系统上也是如此。如 OP 的代码示例所示,bash 命令前面必须有一个感叹号 (!)。

然而,真正的关键是从Git BashUbuntu on Windows 启动。

我正在运行 Windows 10 Pro,并通过 Anaconda 安装了 Python,以下代码在我通过 Git Bash 启动 Jupyter 时有效,但在我从 Anaconda 提示符启动时无效。

>>> !ls
database.sqlite
Weather Data Clustering using k-Means.ipynb

>>>!pip show lxml | grep Version
Version: 4.1.0

【讨论】:

  • 它似乎依赖于支持! 的核心(“内核”)。使用 Python 它可以工作,但不能使用 JavaScript 核心 (IJavaScript)。
【解决方案2】:

安装Git Bash for Windows 对我有用。之后,从那里运行 jupyter notebook。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-24
    • 2019-07-13
    • 1970-01-01
    • 2018-12-12
    • 2016-12-06
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多