Karan Purohit
Karan Purohit

Reputation: 519

using bash commands in jupyter notebook

I never used bash with jupyter notebook. For some project, I need to use bash with python but it's giving me errors. I have installed bash kernel also.

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

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

Upvotes: 6

Views: 41202

Answers (2)

Mesecond
Mesecond

Reputation: 1

Installing Git Bash for Windows did it to me. After that, run the jupyter notebook from there.

Upvotes: 0

Karl Baker
Karl Baker

Reputation: 913

It is possible to use bash commands in Jupyter Notebook, even on Windows systems, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64). As shown in the OP's code example, the bash command must be prepended by an exclamation mark (!).

The real key, however, is launching from Git Bash or possibly Ubuntu on Windows .

I'm running windows 10 Pro with Python installed via Anaconda, and the following code works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt.

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

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

Upvotes: 13

Related Questions