Well, it’s not just ipads, it’s mobile phones.

Pain points

I have organized several offline programming workshops where I have led my students on data science problems in Python.

One of the biggest headaches is the installation of the running environment.

To be honest, I had made careful preparation before attending the workshop.

For the integrated environment, for example, the user-friendly Anaconda was chosen.

The code runs on my Macbook, no problem. Also get the student’s Windows 7 run, there is no problem. That’s when it was posted to Github.

I’ve also written detailed instructions for installing the package in the tutorial post.

Videos have also been recorded on the installation and running of Anaconda, the Python runtime environment.

However, the problems encountered in the workshop were still varied.

Some are operating systems. For example, you might use Windows 10. To be honest, I haven’t. When I looked at the Surface, I couldn’t even find the Anaconda folder after the installation.

There’s coding. Different operating systems, some default Chinese encoding is UTF-8, some GBK. The same section of Chinese text, HERE I show everything is normal, you there is garbled.

There are suite paths. Before coming to the workshop, you may have seen some of my tutorials and installed Python version 2.7 Anaconda. When you arrive at the site and see that Python 3.6 is required, you install a new copy. As a result, you can’t tell which package the Python, PIP commands came from, or where the package was installed. Add to that virtual environment configuration, and you’re going crazy.

There are even congestion problems. Because sometimes you need to install bulky software packages on site, dozens of computers “ready” to compete for limited Wifi bandwidth, the consequences can be imagined.

I decided to change the situation.

The current tutorial provides only the base source code. For many novice students, it is not enough.

Many students fall into the path of installing dependent packages and then simply give up.

There are many workarounds. For example, just record a code execution video for you.

But as I wrote in What Matters most about MOOC teaching? As mentioned in the article, feedback is the most important part of learning.

You need to be able to run the code and get feedback on the results first.

On top of that, you need to be able to modify the code and compare the results before and after.

I need to provide you with a working environment.

Zero installation, naturally there is no trouble.

Is it possible?

I looked into it. It’s fine.

As long as you have a modern browser (including but not limited to Google Chrome, Firefox, Safari and Microsoft Edge) on your device.

Internet explorer 8.0?

That’s no good. Upgrade now!

By this point, you should have figured it out. It’s browser only, not OS, so you can run code on an iPad, not Windows 10.

try

Please open your browser and enter this link (http://t.cn/R35fElv).

See what happens?

I’m going to show you on my iPad.

There will be a startup screen at the beginning. Please wait a few seconds.

You should then see the familiar Python code running interface.

This interface is from Jupyter Lab.

You can think of it as an enhanced version of Jupyter Notebook, which has the following features:

  • Code unit direct mouse drag;
  • A browser TAB that opens multiple notebooks, each using a different Kernel;
  • Markdown editor for real-time rendering;
  • Complete file browser;
  • CSV data files are quickly viewed

The left column in the figure shows all the files in the working directory.

On the right is the ipynb file that we’re going to use.

To prove this is not a joke, click the Run button in the toolbar above the code on the right.

One click will run the result of the current unit of code.

Keep clicking down and you can see that the results are rendered normally.

Even the images display normally.

Even the following visualization, which requires a certain amount of computation, is fine.

To prove that this isn’t magic, you can write a line of output in a new cell.

Let Python print your name.

If your name is Chuck, write:

print("Hello, Chuck!" )Copy the code

Replace it with your own name and see if the output is correct?

It’s more than just an iPad, right?

You can do it under kuang Kuang as well if you’re brave enough to sang, xin, bing, and try it as kuang.

Just like that.

process

Now LET me tell you how this effect is made.

We need a tool called MyBinder. It helps us quickly turn a code repository (REPO) on Github into a running environment.

Note that MyBinder provides us with cloud infrastructure, namely computing resources and storage resources. So even if many users are online at the same time using the same code, the transformed environment does not conflict with each other.

Let’s start by looking at how to prepare a repository for myBinder to convert smoothly.

The sample I provided for you is here (t.cn/R35MEqk) :

Incidentally, this example comes from my data science tutorial Spacy and Word Embedding. If you are interested, you can click on the link to see the original article.

In the list of files displayed on the GitHub page, here are three that you should be aware of:

  • demo.ipynb
  • environment.yml
  • postBuild

Demo. ipynb is the Jupyter Notebook file with the source code that you saw in the previous section. You need to first install the relevant packages locally and run tests to pass.

If you run it locally with errors, you can’t run it in the cloud.

The environment.yml file is important to tell MyBinder how to prepare the environment for your code to run.

Let’s open and look at the contents of the file:

dependencies:
  - python=3
  - pip:
    - spacy
    - ipykernel
    - scipy
    - numpy
    - scikit-learn
    - matplotlib
    - pandas
    - thinc
Copy the code

This file first tells MyBinder your Version of Python. We used version 3.6. So just specify Python =3. Mybinder will automatically download and install the latest ones for you.

This file then describes which packages need to be installed using the PIP tool. We need to list all the installation packages we rely on.

These are the preparation steps that I’ve always shown you in the tutorial.

But that’s not all, because MyBinder just installs some software dependencies for you.

There are two more steps to take care of:

  • To analyze the semantics, we need to call the pre-trained Word2vec model, which myBinder downloaded in advance for us.
  • After the Jupyter Notebook is opened, the kernel name should be Wangshuyi, which has not been registered in Jupyter yet. We need MyBinder.

To complete the above two steps, you need to prepare a final postBuild file.

It reads as follows:

python -m spacy download en
python -m spacy download en_core_web_lg
python -m ipykernel install --user --name=wangshuyi
Copy the code

Like its name. This is executed sequentially after myBinder has installed the dependency build according to environment.yml. If your code needs other commands to provide environment support, you can also put them here.

That’s the end of your preparation.

The magic show has officially begun.

Please open myBinder’s url (mybinder.org/).

In the “GitHub repo or URL” column, fill in our GitHub repository link, namely:

https://github.com/wshuyi/demo-spacy-text-processing
Copy the code

You want to open Demo. ipynb as soon as you enter the page. Therefore, enter Demo. ipynb in Path to a Notebook file (optional).

You’ll find the URL below “Copy the URL below and share your Binder with others:” and the URL of the environment your code runs in.

https://mybinder.org/v2/gh/wshuyi/demo-spacy-text-processing/master?filepath=demo.ipynb
Copy the code

Click the “copy” button on the right to save it to your notepad. It will be up to you to find the right operating environment for your conversion.

Once the address is safely saved, click the “Launch” button.

Depending on the number of dependencies you have installed and other factors, the amount of time you need to wait will vary. But only for the first build, it takes some time.

Each subsequent call will be executed very quickly.

Once built, MyBinder automatically opens the environment for us.

Have a sense of achievement!

Let’s test it out. If it works, we’re successful.

But you’ll find, no!

Teacher, isn’t the advanced version of Jupyter Lab shown by you just now? Why is it a Jupyter Notebook again?

I want the premium version too!

Don’t worry.

Look at your current link address:

https://mybinder.org/v2/gh/wshuyi/demo-spacy-text-processing/master?filepath=demo.ipynb
Copy the code

All you need to do is make a small adjustment and add:

? filepath=Copy the code

Replace with:

? urlpath=lab/tree/Copy the code

The replacement link is:

https://mybinder.org/v2/gh/wshuyi/demo-spacy-text-processing/master?urlpath=lab/tree/demo.ipynb
Copy the code

Type it into your browser and see what it looks like:

Is that all right?

The principle of

Do you think MyBinder is a dark technology?

Actually, not really.

It’s just linking technologies that already exist.

Perhaps this is an example of “building block innovation”.

Let’s look at myBinder’s description:

It can be seen that the most critical technology is docker.

What is a Docker?

Simply put, Docker is a guarantee tool for the smooth execution of the same code on different platforms.

You’re wondering, isn’t that Java?

Yes, the mantra of Java is code once, run everywhere.

It uses virtual machines to secure this capability.

However, if you regularly use tools developed in Java, you should know what the pain points are.

At the very least, you should have some sense of how fast Java programs can run.

In the image above, the virtual machine is on the left and the Docker is on the right.

Docker is not only more efficient than the Java virtual machine, it also supports more than one programming language.

As for the other benefits, we won’t go into that. Otherwise it sounds like an AD.

Mybinder does not convert the Github repository into docker images.

It calls a different tool called repo2Docker (github.com/jupyter/rep…). .

Your Browser can execute Python code because Jupyter Notebook (or Lab) is built on a Browser/Server (B/S) structure.

If you already have Anaconda installed on your local computer, look at executing locally:

jupyter lab
Copy the code

What happens?

Yeah, it opens up a server, and it opens your browser, and it communicates with that server.

The design of Jupyter itself makes it very easy to expand.

It makes no difference whether the Jupyter server is running on your local laptop or in a computer room on another continent.

Also, if you think MyBinder will only let you run Python code on your browser, you’re underthinking it.

For those of you who have studied R, please click on this link (t.cn/R3JLY2S) to see what surprises there are.

summary

To sum up, this article tells you the following:

  • How to convert a Github repO into a Jupyter Lab operating environment with myBinder;
  • How to run the environment, write, execute and modify the code on browsers of various operating systems;
  • Mybinder transforms github Repo behind the hero docker profile.

I hope you can think of more than this simple use.

Here are a few questions for you to ponder:

  • If the code execution is completed in the cloud, is there any need to preinstall a lot of software in the computer room of the teaching laboratory and update it periodically?
  • Would it be possible for school programming exercises, assignments, and exams to be done directly and remotely in this way, and automatically graded?
  • Since the technology is open source, is it possible for you to start a startup using these open source tools? For example, provide deep learning environment, lease to research institutions and startups?

I look forward to your interesting and meaningful innovations.

discuss

What’s it like to run Python code on the iPad? Have you ever used a similar product? What other interesting applications do you think this technology could have in your daily work and study? Welcome to leave a message, share your experience and thinking to everyone, we exchange and discuss together.

If you are interested in my article, please like it and follow my wechat account “Nkwangshuyi”.

If this article may be helpful to your family or friends, you are welcome to share it with them on Weibo or wechat moments. Get them involved in the discussion.

read

How to get started with data science effectively?