【问题标题】:Attempted relative import in non-package when running a Python code运行 Python 代码时尝试在非包中进行相对导入
【发布时间】:2014-06-01 04:25:47
【问题描述】:

我是 Python 新手,不知道如何运行 this code。我收到以下错误:

mona$ python spectral.py 
Traceback (most recent call last):
  File "spectral.py", line 12, in <module>
    from ..base import BaseEstimator, ClusterMixin
ValueError: Attempted relative import in non-package


>>> from ..base import BaseEstimator, ClusterMixin, TransformerMixin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package

我不确定我应该从该存储库下载哪些其他文件,或者我应该下载哪些软件包才能运行此代码。

【问题讨论】:

    标签: python github import repository scikit-learn


    【解决方案1】:

    为什么要运行该脚本?

    安装 scikit-learn。

    sudo pip install scikit-learn
    

    然后你可以在你的 python 脚本中导入光谱聚类:

    阅读: http://scikit-learn.org/stable/auto_examples/cluster/plot_lena_segmentation.html#example-cluster-plot-lena-segmentation-py

    http://scikit-learn.org/stable/auto_examples/cluster/plot_segmentation_toy.html#example-cluster-plot-segmentation-toy-py

    【讨论】:

      【解决方案2】:

      你必须将它作为一个包来运行,而不仅仅是组件。

      您是否已经安装了 sklearn 包和依赖项?

      如果没有,您应该查看 this page 并从那里安装和配置软件包。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-28
        • 2019-05-25
        • 2014-01-02
        • 1970-01-01
        • 2015-12-08
        • 2014-11-14
        • 1970-01-01
        • 2020-07-20
        相关资源
        最近更新 更多