【问题标题】:I get error , cannot import from file helper我收到错误,无法从文件助手导入
【发布时间】:2021-05-23 07:13:36
【问题描述】:

请帮忙,我在运行 jupyter notebook 时遇到以下错误。

import numpy as np
import pandas as pd
from helper import boston_dataframe

np.set_printoptions(precision=3, suppress=True)

错误:

ImportError                               Traceback (most recent call last)
<ipython-input-3-a6117bd64450> in <module>
      1 import numpy as np
      2 import pandas as pd
----> 3 from helper import boston_dataframe
      4 
      5 

ImportError: cannot import name 'boston_dataframe' from 'helper' (/Users/irina/opt/anaconda3/lib/python3.8/site-packages/helper/__init__.py)

【问题讨论】:

  • 我怀疑你安装了helper,也就是这个代码:github.com/gmr/helper 可以从helper 项目下的pypi 获得。它不包含boston_dataframe 变量。所以这里的问题是你打算为这个笔记本使用哪个helper?这个笔记本是否有 helper 代码?
  • 笔记本附带了一个帮助文件。我已经下载了。它适用于其他笔记本,但不适用于这个
  • 这似乎是一个相对路径。请参阅下面的答案。如果您想更普遍地使用它,那么您将希望以多种方式包含它,例如将目录添加到 PYTHONPATH。但是在同一个地方有这个特定的代码会很清楚你正在使用哪个helper library/module。

标签: python


【解决方案1】:

由于您没有提供笔记本的来源,我不得不猜测您是从 Supervised Learning: Regression 提供的 IBM 课程中获得的。

在第 1 周的 zip 文件夹中,它提供了helper.py

您需要做的是将目录更改为该文件所在的位置。 Change IPython/Jupyter notebook working directory

或者,您可以从sklearn 加载波士顿数据,然后将其加载到Pandas Dataframe

给你的建议:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2015-10-09
    • 2021-11-08
    • 2015-07-22
    • 1970-01-01
    • 2019-06-10
    相关资源
    最近更新 更多