Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter Notebook : 'head' is not recognized as an internal or external command, operable program or batch file

I tried to view my CSV file using

!head {train_file_path} 

in jupyter notebook.But it raises an error

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

!head{} works in colab but not in Jupyter Notebook.

please help me, guys . Thanks in advance

like image 543
BSP Avatar asked May 12 '20 09:05

BSP


Video Answer


3 Answers

Using ! means that you will be calling a system command. If you are on a Linux/Unix system (Google Colab uses such system) then you can call Linux/Unix commands directly using !. In this case, I am assuming that you are using a Windows system and the command head does not exist as a command for Windows. Assuming that you are using a locally hosted Jupyter Notebook, then it is running on a Windows system.

You can do something similar through Python using:

with open({train_file_path}) as f:
    for _ in range(10): # first 10 lines
        print(f.readline())
like image 169
David Avatar answered Oct 13 '22 01:10

David


%%bash works for me

or

conda install posix 

https://github.com/jupyter/help/issues/203

like image 42
Biobeer Avatar answered Oct 12 '22 23:10

Biobeer


I had the same issue even if I installed the Linux Subsystem for Windows and tried to refer Jupyter Lab to bash.exe. This seems to work for terminal sessions in Jupyter Lab, but not in the notebook cells.

A workaround for me was to add a %%bash at the beginning of each cell with bash commands. Then also remove the ! from the actual commands, like so

%%bash
head iris.csv

Still cannot make it work with an ! directly, but at least it works.

like image 20
Misa Avatar answered Oct 13 '22 00:10

Misa