Running powershell commands through jupyter

I am launching jupyter notebook from a miniconda powershell prompt. Jupyter notebook opens and runs as expected. However, when I attempt to run a powershell command as follows:

!ls

I get an error:

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

Which indicates to me that it is not powershell which runs under the hood, but cmd. This is strange because, as I previously mentioned, I am actually launching the notebook via a powershell prompt.

Is there anything I can do to make sure I have powershell behind the scenes when I run my jupyter notebook?

Thanks

Yeah, cmd.exe is terrible and broken… but has the “feature” of being terrible and broken the same way everywhere, so is a sensible default from a portability point of view.

Not a windows user (by choice) myself, but a quick SO hunt suggests:

import os
os.environ.update(comspec="powershell.exe")

Depending on… things… you might need to give a full path to powershell.exe

No idea what other impact this would have but it might do the trick… but mostly, it’s unlikely to do anything terrible to the rest of your computer!

3 Likes