Open shanedante opened 7 years ago
I don't think there's a good way to have it call git-bash on Windows. For ls specifically, we have a %ls
magic which is an alias to the Windows dir
command.
I was also facing the same issue, while going through those tutorials. However in place of ! as mentioned in the tutorial we need to place % and it works fine in windows 10.
So instead of !ls use %ls and click Shift+Enter, it displays the list of directories. Please see below snip.
Hope it helps
There are magic aliases for a few command commands like %ls
, but not for all Unix commands.
I happen to stumble on this thread as I'm doing the same course as @shanedante. If you install Git Bash and check the box to add the UNIX tools to your PATH, you will be able to simply run the commands like !ls
.
The problem I had was with sed and deleting empty lines as Jupyter calls CMD.exe - I wish there was a setting in Jupyter to set which shell to use :)
I'm just starting with pyttohn and I have the same problem. could it be realted with PowerShell? I installed git and the unix commands work well in powershell but no in CMD.
@raavello This is what we're trying to figure out.
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:
Use Git and the optional Unix tools from the Windows Command Prompt
. C:\Users\Bob
).source Anaconda3/Scripts/activate Anaconda3/
cd
into the folder where the course notebooks are.
Example: cd Projects/dse200x/week-3/week-3-unix/
jupyter notebook
and your browser should open with Jupyter in the current directory.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
Good luck!
@cristovaov thank you!
Thanks @cristovaov !! You just saved the day!!
When I open the Git Bash and type:
source Anaconda3/Scripts/activate Anaconda3/
I get: invalid Syntax.
Does anyone know what could be wrong?
Thank you @cristovaov now Jupyter notebook runs
The simple solution for the guys who ever getting errors while running Unix commands over jupyter notebook( through Anaconda3) is
-> Need to install git bash -> check current directory $pwd
c : \user\praveen
-> run jupyter notebook command
$ jupyter notebook
which will open note book and where we can run all Unix commands ex: !cat, !head, !ls....etc
I actually did have the need to run git-bash from a notebook running in a Windows Python environment, and managed to get data out of it via the following arcane invocation:
import subprocess, pathlib, tempfile
GIT_BASH = r"C:\Users\NickCoghlan\AppData\Local\Programs\Git\git-bash.exe"
def run_git_bash_cmd(cmd):
with tempfile.TemporaryDirectory() as tmpdir:
target = pathlib.Path(tmpdir) / "output_file"
dirname, fname = target.parts[-2:]
sh_target = f"/tmp/{dirname}/{fname}"
git_bash_cmd = [GIT_BASH, "--hide", "--no-needs-console", "-lc", f"{cmd} > {sh_target}"]
print(git_bash_cmd)
cmd_result = subprocess.run(git_bash_cmd)
print(cmd_result)
cmd_result.check_returncode()
with target:
result = target.open().read()
return result
print(run_git_bash_cmd("env"))
is then a handy way of checking whether or not the command is working as expected. (Note that my specific snippet runs a git-bash login shell, since I wanted ssh-agent to start automatically)
I am working with Numpy and Pandas using Anaconda(Python) and Jupyter Notebooks on Windows 10.
I tried using Unix commands in Jupyter like !ls but the notebook says the command is not recognized. I was told I have to use Gitbash which I downloaded but I am unsure how to connect Gt bash to the notebook so the Unix commands will work.
I launch jupyter notebook with the jupyter command prompt and type (jupyter notebook) and it loads in a browser. However, I have no idea how to use the GitBash with the notebook. But when I type in ! ls in gitbash, I see all of the files I need to work with. Can someone please help me connect this? https://courses.edx.org/courses/course-v1:UCSanDiegoX+DSE200x+2T2017/discussion/forum
/