6

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.

3
  • What operating system are you using? Commented Jan 31, 2018 at 10:33
  • {PATH} isn't really a valid Bash expression. Perhaps you mean ${PATH} (where however the braces aren't really useful or necessary)? (Not too familiar with Jupyter though.) Commented Jan 31, 2018 at 10:39
  • using windows 8.1 Commented Jan 31, 2018 at 10:44

3 Answers 3

13

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
Sign up to request clarification or add additional context in comments.

1 Comment

It seems to depend on the core ("kernel") supporting the !. With Python it works but not say with the JavaScript core (IJavaScript).
1

Just put %%bash as the first line in your jupyter cell

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.