gpt4 book ai didi

python - 在 jupyter notebook 中使用 bash 命令

转载 作者:行者123 更新时间:2023-12-03 20:30:39 26 4
gpt4 key购买 nike

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

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

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

最佳答案

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

然而,真正的关键是从 Git Bash 启动或可能 Ubuntu on Windows .

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

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

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

关于python - 在 jupyter notebook 中使用 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48539900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com