sr320 / course-fish546-2018

7 stars 2 forks source link

Connecting Git Bash and Jupyter #19

Closed Jeremyfishb closed 5 years ago

Jeremyfishb commented 5 years ago

I've tried searching the web but still can not figure out how to link Git Bash to Jupyter notebook in Windows. Have any other Windows users or our instructors had any luck with this yet?

sr320 commented 5 years ago

see https://github.com/sr320/course-fish546-2018/issues/15

Jeremyfishb commented 5 years ago

Thanks. I tried Sam's tutorial but when I try to look at my .bash_profile (command: cat ~/.bash_profile), it says there is no such file or directory.

However, I searched my computer for the .bash_profile and found this: "C:/Program Files/Git/etc/profile.d/bash_profile" which is down a different path than my default (C/Users/jeremy axworthy/).

I tried the cat command with that absolute path but it still says no such file or directory.

Could this be an issue with where my applications are stored? I could try re-installing all of the programs to the same location?

kubu4 commented 5 years ago

Updated Jupyter instructions:

Do the following from a Git Bash terminal. Press "Enter" after each step.

  1. USER=$(whoami)

  2. echo "export PATH=$PATH:/c/Users/${USER}/Anaconda3:/c/Users/${USER}/Anaconda3/Scripts/jupyter:/c/Users/${USER}/Anaconda3/Library/bin" >> ~/.bash_profile

To see if this whole thing worked.

  1. Close Git Bash.
  2. Open Git Bash.
  3. Type: which jupyter

If it worked, that command should return something like this: /c/Users/Samb/Anaconda3/Scripts/jupyter

kubu4 commented 5 years ago

I have the actual solution to this! I have tested on a Windows 7 computer only, but it works perfectly.

  1. If you've installed Anaconda, uninstall it (will be listed as Python something something Anaconda, if using Control Panel).

  2. Install Anaconda.

  3. When you get to the prompt about adding Anaconda to the system path, check the box to do so (the recommendation of the dialog box is to not check the box; do it anyway).

  4. After installation is complete, start Git Bash.

  5. In Git Bash, type: which jupyter

If it worked, that command should return something like this: /c/Users/Samb/Anaconda3/Scripts/jupyter

Now, you should be able to launch a Jupyter notebook by typing: jupyter notebook in the Git Bash terminal!

To run bash commands in the Jupyter notebook, always enter %%bash as the first line of the cell. Then, type your bash commands on a different line of the cell.

NOTE: Some commands (like cd and ls) will not work in a Jupyter notebook cell that starts with the %%bash designation!

Jeremyfishb commented 5 years ago

It worked! Thank you Sam. Now I have so many shells to choose from...

jgardn92 commented 5 years ago

It worked for me too in GitBash but still can't make it work with Ubuntu. But at least it's working on something! Thanks so much Sam

jgardn92 commented 5 years ago

So I hit at snag when I started trying to actually do things in Jupyter Notebooks in GitBash. It seems that my PATH environment in my jupyter notebook is empty so bash can't find basic commands like gunzip. These commands still work in GitBash but not in Jupyter. I'm guessing there's something I need to do to assign the path in Jupyter but I am not sure how to go about doing that.

kubu4 commented 5 years ago
  1. Please post screen cap of problem.

  2. Did you launch Jupyter notebook from GitBash? If not, you need to launch Jupyter notebook in this fashion.

  3. Use Ubuntu instead (honestly, it's preferable to using GitBash). If you need help getting Jupyter notebook to work with Ubuntu, see my instructions for installing Anaconda in Ubuntu.

sr320 commented 5 years ago

I realize this is not very elegant... but could she not simply use the absolute path ..

for example checking where it is

sr320$ which gunzip
/usr/bin/gunzip

For bioinformatic specific programs I am suggesting they use absolute paths ... so it will not be much different.

kubu4 commented 5 years ago

which command won't work for her, if gunzip (or other commands) are not in her system PATH.

Just calling gunzip would execute /usr/bin/gunzip, if it's in her system PATH. The which command just looks at what's in the system PATH, so if calling gunzip didn't work, then using which won't work to find gunzip either.

However, I've verified on that I can use gunzip in a Jupyter notebook launched from GitBash.

I think we'll have to see her response to try to troubleshoot.

jgardn92 commented 5 years ago

Here's a screen cap of the problem. I did launch Jupyter from GitBash. I got it installed in Ubuntu but I was struggling to use Jupyter from there. gunzip trouble

kubu4 commented 5 years ago

The issue you're having is related to the formatting of your cells.

When using a bash command in a cell, you should always have the following as the first line of your cell (see my comment earlier in this issue):

%%bash

What you're experiencing is some behind-the-scenes junk that takes place when you use the ! notation. This should be avoided.

Your echo command will also fail (in your notebook above, you neglected the ! like you used in your other cells), like your gunzip command, when using the ! notation.