How to Upload Jupyter Notebook With Results to Github

Jupyter Notebook is a web-based development tool that makes it easier for developers to manage projects. With a convenient interface, Jupyter includes interactive elements to create and share alive documents that incorporate lawmaking, visuals, equations, and even narrative texts.

I've already written near how to install Jupyter Notebook in my piece "Jupyter Notebooks: The Web-Based Dev Tool You've Been Seeking," so you should read through that tutorial to get Jupyter up and running.

Thing is, with a default Jupyter installation, you miss out on GitHub integration. And given how so many developers depend on the likes of GitHub, this is a characteristic that is sorely missed.

Fortunately, a developer has created an extension that makes it possible for you to use Jupyter with GitHub. Unfortunately, since the developer created the extension for Jupyter/GitHub, things accept changed on the side of GitHub, so there'south 1 caveat to using this tool (I'll explain later). But even with that caveat, this extension is a practiced way to continue your Jupyter Notebooks in sync with a GitHub repository (otherwise, all of those notebooks will remain on your local machine).

Let'southward get these ii pieces of engineering science connected.

Before y'all offset this process, make sure you've taken care of getting Jupyter installed. Make sure you lot don't launch a notebook yet. Nosotros'll exercise that in a bit.

Installing the Extension

You've already installed the necessary dependencies for Jupyter (Python and pip). You now need to install the Jupyter GitHub extension. Log into your machine that contains Jupyter and open up a last window. From the CLI, issue the post-obit commands:

alias pip=pip3

pip install git+https://github.com/sat28/githubcommit.git

jupyter serverextension enable --py githubcommit

jupyter nbextension install --py githubcommit --user

jupyter nbextension enable githubcommit --user --py

The to a higher place commands will install the extension and make sure it is available for all notebooks.

Install the remaining dependencies

Yous probably already have git installed, only on the off-hazard you don't, issue the command (I'm demonstrating on Ubuntu Desktop 21.04):

sudo apt-get install git -y

If yous're using a Carmine Hat-based distribution, that command would exist:

sudo dnf install git -y

Generate SSH keys

You'll also need SSH keys (so you tin can clone the necessary repository). For this, run the command:

ssh-keygen

Brand sure to accept the defaults and give the cardinal a unique and strong password.

Once you've generated the key, view the public key with the command:

less ~/.ssh/id_rsa.pub

Copy the contents of that fundamental and head over to your GitHub business relationship. Go to Settings > SSH and GPG keys and click New SSH Key. In the resulting window, paste the SSH key you just generated, give it a name, and click Add SSH Key (Effigy 1).

Figure one: Adding an SSH central to GitHub.

Clone the Repository

We demand to clone the extension repository, with the command:

git clone [email protected]:sat28/githubcommit.git

You volition be asked for the countersign for your SSH key you just created. When this finishes, a new directory will be created, named githubcommit.

With the repository cloned, let's make sure Git knows who we are. Issue the following 2 command:

git --global user.e-mail EMAIL

git --global user.name Proper name

Where Email is your email address and Proper name is your name.

Create a GitHub Access Token

Next, you need to create a GitHub admission token. Become to your GitHub business relationship and and then to Settings > Programmer Settings > Personal Access Tokens. Click Generate New Token and so, in the resulting window, give it a name and check the boxes for repo and write:packages. Scroll to the bottom and click Generate token. You'll then need to re-create that access token to your clipboard.

Configure the Extension

Change into the githubcommit folder with the command:

cd githubcommit

Open the env.sh configuration file with the command:

nano env.sh

In that file, you must configure the following section:

Where:

  • REPONAME is the proper name of a GitHub repository yous'll use for this.
  • BRANCH is the repository branch (probably "main")
  • USERNAME is your GitHub username
  • Email is the email accost associated with your GitHub business relationship
  • ATOKEN is the access token you but created.

Relieve and close the file.

Source the env.sh file and launch a notebook

The adjacent step is to source the env.sh file with the command:

source ~/githubcommit/env.sh

You will exist prompted for your SSH key password. In one case you've done that, the repository you configured in the env.sh file will clone to your local bulldoze (in your home directory). When that completes, alter into the new directory that cloned from your GitHub repository (in my case it was named newstack).

From within that directory, launch the notebook with the command:

jupyter notebook --ip 0.0.0.0

Your notebook should open to reveal all of the files from your GitHub repository (Effigy 2).

Figure 2: Jupyter Notebook with files from the newstack repository I created.

If you create a new file or open 1, you'll at present see a GitHub logo in your notebook (Figure 3).

Effigy 3: The GitHub logo now shows up in the Jupyter Notebook.

Here's where the caveat comes into play. You should exist able to click that button and then commit whatever new code to the continued GitHub repository. Unfortunately, it'southward not working. I have a feeling this is considering of the changes GitHub has made recently to hallmark. Because of that, it's on the developer to set this trouble.

Fortunately, I have a workaround.

After you've created all of your new files and are finished working in Jupyter Notebook, they'll all exist found in the directory pulled down from your configured GitHub repository. In my case, I used a test repository I created on GitHub, named newstack.

Modify into that folder and and then go through the usual process with git:

git add .

git commit -thousand "Added new files"

git button

Once y'all've taken care of the to a higher place steps, all of your new files will exist uploaded to the GitHub repository.

The 2d caveat is that Jupyter doesn't automatically pull down any new files created past other teammates or from within GitHub itself. For that, go dorsum to the terminal window and issue the command:

git pull

In other words, to push and pull new content to and from GitHub, you must utilise the control line (at least until the programmer fixes the issue). But even with having to do this, being able to integrate Jupyter Notebooks with GitHub makes the tool even more useful.

Hopefully, quondam presently, the programmer will resolve the event with the push button and pull of content. Until then, you can get around the issues with a little transmission git pull and git push.

murrayfithe1974.blogspot.com

Source: https://thenewstack.io/integrate-jupyter-notebooks-with-github/

0 Response to "How to Upload Jupyter Notebook With Results to Github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel