简体   繁体   English

Python:使用 Jupyter Notebook 运行代码(在线)

[英]Python: Running Code using Jupyter Notebook (Online)

I am new to the world of Python.我是 Python 世界的新手。 I am using a computer with very little space left, so I decided to try to use the online version of Python without explicitly installing anacondas or python.我正在使用剩余空间很小的计算机,因此我决定尝试使用在线版本的 Python 而不显式安装 anacondas 或 python。

I used this link over here: https://notebooks.gesis.org/binder/jupyter/user/ipython-ipython-in-depth-eer5tgdf/notebooks/binder/Index.ipynb# , and then I opened a new file.我在这里使用了这个链接: https://notebooks.gesis.org/binder/jupyter/user/ipython-ipython-in-depth-eer5tgdf/notebooks/binder/Index.ipynb# ,然后我打开了一个新文件。 I am trying to re-run the code from this github repository: https://github.com/brohrer/byo_decision_tree/blob/main/decision_tree.py我正在尝试从这个 github 存储库重新运行代码: https://github.com/brohrer/byo_decision_tree/blob/main/decision_tree.py

I tried running the following code and got this error:我尝试运行以下代码并收到此错误:

import numpy as np
import matplotlib.pyplot as plt

from tree_node import TreeNode

import numpy as np
import matplotlib.pyplot as plt
​
from tree_node import TreeNode
​
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-984dee29eb66> in <module>
      2 import matplotlib.pyplot as plt
      3 
----> 4 from tree_node import TreeNode

ModuleNotFoundError: No module named 'tree_node'

This line is preventing me from running the rest of the code.这条线阻止我运行代码的 rest。 Can someone please show me what am I doing wrong?有人可以告诉我我做错了什么吗?

  1. Is it simply not possible to run python code online without having downloaded anaconda?没有下载 anaconda 就无法在线运行 python 代码吗?

  2. Or am I approaching this problem the wrong way?还是我以错误的方式处理这个问题? Perhaps the version of python I am using is incorrect?也许我使用的 python 版本不正确? Or there are some dependencies required that I have not yet installed.或者有一些我还没有安装的依赖项。

Can someone please show me how to resolve this problem?有人可以告诉我如何解决这个问题吗?

Thanks谢谢

在此处输入图像描述

To simplify the development different functionalities are allocated to different scripts/modules.为了简化开发,不同的功能被分配给不同的脚本/模块。

You are simply taking the main script ( decision_tree.py ) and trying to run it.您只是在使用主脚本 ( decision_tree.py ) 并尝试运行它。 But it has some imports from other modules.但它有一些来自其他模块的导入。 For example, in the directory where you opened decision_tree.py , there is also tree_node.py , which has TreeNode class, which is imported into decision_tree.py .比如你打开decision_tree.py的目录下,还有tree_node.py ,里面有TreeNode class,导入decision_tree.py

So, one of the options is to copy this TreeNode class into decision_tree.py and put it above DecisionTree class.因此,一种选择是将此TreeNode class 复制到decision_tree.py并将其放在DecisionTree class 上方。

You can use Google Colab.您可以使用 Google Colab。 It is free and you can access it from your google drive account.它是免费的,您可以从您的谷歌驱动器帐户访问它。 Basically Colab is a Jupiter notebook running on cloud.基本上 Colab 是一个在云上运行的 Jupiter notebook。 If you are familiar with Jupiter notebook, you will learn Colab quickly.如果你熟悉 Jupiter notebook,你会很快学会 Colab。

For more Information: Google Colab更多信息:谷歌 Colab

Did you try to?pip install tree_node.你试过吗?pip 安装tree_node。 No module usually means module not installed.没有模块通常意味着未安装模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM