In fact, it’s not just iPads, mobile phones can also be used. Pain Points I have organized several offline programming workshops, leading students to use Python to solve data science problems. The most troublesome thing is the installation of the operating environment. To be honest, I had made serious preparations before attending the workshop. For example, for the integrated environment, we chose the user-friendly Anaconda. The code ran on my Macbook computer without any problems. I also ran it on my student's Windows 7 computer without any problems. Then I uploaded it to Github. In the published tutorial article, I have also written very detailed instructions for installing the software package. A video was also recorded specifically for the installation and operation of Anaconda, a Python runtime environment. However, the problems encountered at the workshop are still varied. Some are operating systems. For example, you may use Windows 10. To be honest, I have never used it. I looked at the Surface carefully and couldn't even find the Anaconda folder after installation. Some are encodings. Different operating systems have default Chinese encodings of UTF-8 and GBK. The same Chinese text may appear normal on my screen but garbled on yours. Some are package paths. Before coming to the workshop, you may have watched some of my tutorials and installed Anaconda for Python 2.7. When you arrived, you saw that you needed Python 3.6, so you installed a new one. As a result, when you run it, you can't tell which package the Python and pip commands you run come from, and you can't figure out where the software packages are installed. Add to that the virtual environment configuration, and you'll go crazy. Others even face network congestion issues, as sometimes large software packages need to be installed on-site, and dozens of computers are "ready-to-go" to compete for limited Wifi bandwidth, with predictable consequences. After learning from my mistakes, I decided to change the status quo. The current tutorial only provides basic source code, which is not enough for many novice students. Many students failed on the road of installing dependent software packages and then simply gave up. There are many workarounds, such as recording a video of the code execution for you to watch. But as I said in the article "What is the most important thing in MOOC teaching?", feedback is the most important thing in the learning process. You need to be able to run your code and get immediate feedback on the results. On this basis, you must also be able to modify the code and compare the execution results before and after. I have to provide you with an environment where you can run it directly. With zero installation, there is naturally no need for the above troubles. Is this possible? I researched it and it's ok. All you need is a modern browser on your device (including but not limited to Google Chrome, Firefox, Safari, and Microsoft Edge, etc.). IE 8.0? That won't work, upgrade now! After reading this, you should have figured it out. Because it only selects the browser, not the operating system, so let alone Windows 10, you can run the code even if you are using an iPad. try Please open your browser and enter this link (http://t.cn/R35fElv). See what happens? I'll demonstrate this to you using an iPad. At first, a startup interface will appear. Please wait for about 10 seconds. Then, you can see the familiar Python code running interface. This interface comes from Jupyter Lab. You can think of it as an enhanced version of Jupyter Notebook, which has the following features:
The left column in the figure shows all the files in the working directory. The file opened on the right is the ipynb file we are going to use. To prove that I am not kidding, please click the Run button in the toolbar above the code on the right. Click it and the result of the current code unit will be run. Keep clicking and you can see that the results are rendered normally. Even the images are displayed normally. Even the following visualization results that require a certain amount of calculation are no problem. To prove that this is not magic, you can write a line of output statements in a new cell. Just let Python output your name. If your name is Chuck, you would write:
Replace it with your own name and see if the output is correct? In fact, it’s more than just the iPad. If you are brave enough to try, mobile phones can also be used. Just like this. process Now let me tell you how this effect is achieved. We need to use a tool called mybinder. It can help us quickly convert a code repository (repo) on GitHub into a runnable environment. Note that mybinder provides us with cloud facilities, that is, computing resources and storage resources. Therefore, even if many users use the same code-converted environment online at the same time, there will be no conflict. Let's first take a look at how to prepare a code repository that can be smoothly converted by mybinder. The sample I provide for you is here (http://t.cn/R35MEqk): By the way, this example comes from my data science series tutorial "How to process natural language with Python? (Spacy and Word Embedding)". Interested students can click the link to view the original text. In the list of files shown on the GitHub page, you need to pay attention to the following three files:
demo.ipynb is the Jupyter Notebook file containing the source code you saw in the previous section. You need to first install the relevant packages locally and run the test. If there are errors when you run it locally, it will probably be difficult to run it properly when you put it on the cloud. The environment.yml file is very important. It tells mybinder how to prepare the environment for your code to run. Let's open the file and take a look at its contents:
This file first tells mybinder your Python version. We use version 3.6, so just specify python=3. mybinder will automatically download and install the latest version for you. Then this file describes which packages need to be installed using the pip tool. We need to list all the dependent installation packages. These are the preparation steps that I always explained to you in the tutorials before. But that's not all, because mybinder just installs some software dependencies for you. There are two more steps to take care of here:
To complete the above two steps, you need to prepare a postBuild file. Its contents are as follows:
Just like its name. It is the command that mybinder executes in sequence after installing the dependent components according to environment.yml. If your code needs other commands to provide environment support, you can also put them here. At this point, your preparations are complete. The magic show officially begins. Please open the mybinder website (https://mybinder.org/). In the "GitHub repo or URL" field, fill in our GitHub code repository link, that is:
We hope that demo.ipynb will be opened automatically as soon as we enter the interface, so we need to fill in demo.ipynb in the "Path to a notebook file (optional)" column. At this point, you will find the URL of your code runtime environment in the "Copy the URL below and share your Binder with others:" column.
Click the "Copy" button on the right to save it in your notepad. You will rely on it to find your converted operating environment in the future. Once you have the address saved properly, click the “Launch” button. The time you need to wait may vary depending on the number of dependent installation packages and other factors. But it will take some time only when you build for the first time. Every subsequent call will be very fast. After the build is complete, mybinder will automatically open the corresponding operating environment for us. It's quite a sense of accomplishment! Test it and if the code can run normally, it proves that we are successful. But you will find that it is not true! Teacher, what you just demonstrated on iPad, wasn't it the advanced version of Jupyter Lab? How come it became Jupyter Notebook? I want the premium version too! Don't be in a hurry. Check your current link address: https://mybinder.org/v2/gh/wshuyi/demo-spacy-text-processing/master?filepath=demo.ipynb You just need to make a small adjustment:
Replace with:
The replaced link is: https://mybinder.org/v2/gh/wshuyi/demo-spacy-text-processing/master?urlpath=lab/tree/demo.ipynb Type this into your browser and see what comes out: Is this all right now? principle Do you think mybinder is very high-tech? Actually, not really. It just links together several existing technologies. This can probably be considered an example of "building block innovation". Let's look at the description of mybinder: As you can see, the most critical technology is the use of Docker. What is Docker? Simply put, Docker is a tool that ensures that the same code can be successfully executed on different platforms. You are a little hesitant. Isn't this talking about Java? That’s right, Java’s slogan is to code once and run everywhere. It uses virtual machines to ensure this capability. However, if you often use tools developed in Java, you should understand the pain points. At least, you should have some experience with the running speed of Java programs. In the picture above, the virtual machine is on the left and Docker is on the right. Not only is Docker more efficient than the Java virtual machine, but it also supports more than one programming language. As for other benefits, we won’t go into details, otherwise it will sound like an advertisement. In fact, the work of converting the GitHub code repository into a Docker image is not done by mybinder itself. It calls another tool called repo2docker (https://github.com/jupyter/repo2docker). Your browser can execute Python code because Jupyter Notebook (or Lab) is built on the "Browser / Server" (B/S) structure. If you have already installed Anaconda on your local computer, you can try executing this statement locally:
What will happen? Yes, it starts a server and then opens your browser to communicate with the server. The design of Jupyter makes it extremely convenient to expand. Whether the Jupyter server is running on your local laptop or in a server room on another continent, it makes no difference to the way you execute Python code. In addition, if you think mybinder can only allow you to run Python code in the browser, then you underestimate it. For those who have learned R, please click this link (http://t.cn/R3JLY2S) to see what surprises there are. summary In summary, this article tells you the following:
I hope you can think of more uses than just these simple ones. Here are a few questions for you to think about:
I hope you can draw inferences from this and make interesting and meaningful innovations. |
<<: 8 excellent Android PDF reading apps for viewing documents
>>: HTC launches blockchain phone, is it the last attempt to subvert Or?
From "a piece of paper plan" to the cre...
Author: Xue Qingxin, registered dietitian Reviewe...
Consider the following scenario: Let’s say you ar...
As a search engine media advertising platform, 36...
When driving on the road, safety is the most impo...
During the operation of a product, there is one m...
Dong Mingzhu’s famous quotes and stories are alw...
This article mainly introduces the relevant infor...
On July 4, local time, Volvo Cars launched a new ...
In the first half of 2023, Great Wall Motor's...
The content of SEM bidding hosting provided by Ku...
Although Douyin is relatively more focused on pub...
On Douyin , each short video enters the Douyin tr...
How much does it cost to be an agent for a buildi...
He Xiaopeng, chairman of Xpeng Motors, said: &quo...