help icon indicating copy to clipboard operation
help copied to clipboard

No unix command working in Jupyter Notebook using ! character

Open firdos4u opened this issue 7 years ago • 10 comments

I am not able to run any unix command in notebook using !

Error: command is not recognized as an internal or external command, operable program or batch file.

image

firdos4u avatar Aug 15 '17 18:08 firdos4u

What do you get from %env, especially PATH? What OS and Python version are you using?

minrk avatar Aug 16 '17 11:08 minrk

That looks like a Windows error. On Windows, ! runs Windows commands.

takluyver avatar Aug 16 '17 15:08 takluyver

%env.txt @minrk I am using windows 10 OS. While creating notebook, I am selecting Python 3. On running %env, I am getting following 'PATH': 'C:\Users\Firdaus\Anaconda3\Library\bin;C:\Users\Firdaus\Anaconda3\Library\bin;C:\Users\Firdaus\Anaconda3;C:\Users\Firdaus\Anaconda3\Library\mingw-w64\bin;C:\Users\Firdaus\Anaconda3\Library\usr\bin;C:\Users\Firdaus\Anaconda3\Library\bin;C:\Users\Firdaus\Anaconda3\Scripts;C:\Users\Firdaus\Anaconda3\Library\bin;C:\Program Files (x86)\Intel\TXE Components\TCS\;C:\Program Files\Intel\TXE Components\TCS\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Git\cmd;C:\Users\Firdaus\Anaconda3;C:\Users\Firdaus\Anaconda3\Scripts;C:\Users\Firdaus\Anaconda3\Library\bin;C:\Users\Firdaus\AppData\Local\Microsoft\WindowsApps;',

firdos4u avatar Aug 16 '17 17:08 firdos4u

Oh, yeah. On Windows, you aren't going to find unix commands because it's Windows. Do you see those commands as being available when you run a cmd shell?

minrk avatar Aug 17 '17 15:08 minrk

Is it possible to "emulate" running UNIX commands on Jupyter notebook that is installed on windows?

denisBK avatar Dec 08 '17 00:12 denisBK

You can run the notebook inside a Linux virtual machine (e.g. with Virtualbox), or inside the new 'Windows Subsystem for Linux', which acts a lot like a virtual machine, though it works differently.

There are also projects like Cygwin that try to provide a Unix-like environment on Windows, but we don't really try to support that. It's neither fully one thing nor the other, which makes it confusing.

takluyver avatar Dec 08 '17 10:12 takluyver

Hi, for people taking the UCSD course: I think there's a lot of confusion on your ends. Also I didn't notice before but from the OP first screenshot, you don't do !ls in Git Bash itself - it's simply ls. The ! before a unix command is only in the Jupyter Notebook web interface.

Here's a step by step of my setup:

Install Git Bash - at installation select the optionUse Git and the optional Unix tools from the Windows Command Prompt. Install Anaconda. Uncheck all boxes in the advanced installation screen - see this image. Launch Git Bash. It should open in your user directory (ex: C:\Users\Bob). In the Git Bash terminal activate the Anaconda environment with the command: source Anaconda3/Scripts/activate Anaconda3/ cd into the folder where the course notebooks are. Example: cd Projects/dse200x/week-3/week-3-unix/ Run jupyter notebook and your browser should open with Jupyter in the current directory. When finished, shutdown Jupyter in your terminal with ctrl+c and close the terminal window. Like mentioned in my previous comment, you'll have to modify the sed command and the "deleting empty lines" bit as it behaves differently:

The problem I had was with sed and deleting empty lines as Jupyter calls CMD.exe

Credits: @cristovaov

leandroamoras avatar Mar 16 '18 13:03 leandroamoras

Hi, This solution does not seem to work for me:

When I type: source Anaconda3/Scripts/activate Anaconda3/ it says: invalid syntax.

However, when i just type python it does not give me an error.

But then, when i want to cd into the folder where the course notebooks are. This does not work either: it also says invalid syntax

What do I need to do?

NielsHaw avatar May 31 '18 11:05 NielsHaw

Hi Guys,

This Solution worked for me: conda install posix

kirangupta23 avatar Jun 07 '18 12:06 kirangupta23

Hi Guys,

This Solution worked for me: conda install posix

This worked fine for me. Thank you

riddhitokdar avatar Mar 07 '19 06:03 riddhitokdar