关于 Graphlab 库导入

About Graphlab library importing

在Ubuntu 14.04中,我安装了基于https://dato.com/download/install-graphlab-create-command-line.html的Graphlab,它似乎工作正常。

但是,我在尝试使用推荐模块时收到此错误:

import graphlab 
from graphlab.recommender import ranking_factorization_recommender

第一行导入graphlab没有报错。但是,第二行导致此错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last) 
<ipython-input-5-34df81ffb957> in <module>()
----> 1 from graphlab.recommender import ranking_factorization_recommender

ImportError: No module named recommender

问题如何解决?谢谢

这只是一个命名空间问题。 recommender 实际上存在于 `toolkits 模块中,所以这应该有效:

import graphlab
from graphlab.toolkits.recommender import ranking_factorization_recommender

Graphlab 已经在他们的 __init__.py 文件中为您导入了所有内容。

就这样:

from graphlab import ranking_factorization_recommender
from graphlab import <any_other_recommender>

这是 graphlab.__init__.py 文件的片段:

from graphlab.util import get_runtime_config
from graphlab.util import set_runtime_config

import graphlab.connect as _mt
import graphlab.connect.aws as aws
from . import visualization

import os as _os
import sys as _sys
if _sys.platform != 'win32' or \
    (_os.path.exists(_os.path.join(_os.path.dirname(__file__), 'cython', 'libstdc++-6.dll')) and \
    _os.path.exists(_os.path.join(_os.path.dirname(__file__), 'cython', 'libgcc_s_seh-1.dll'))):
    from graphlab.data_structures.sgraph import Vertex, Edge
    from graphlab.data_structures.sgraph import SGraph
    from graphlab.data_structures.sarray import SArray
    from graphlab.data_structures.sframe import SFrame
    from graphlab.data_structures.sketch import Sketch
    from graphlab.data_structures.image import Image

    from graphlab.data_structures.sgraph import load_sgraph, load_graph

    from graphlab.toolkits._model import Model, CustomModel

    import graphlab.aggregate
    import graphlab.toolkits
    import graphlab.toolkits.clustering as clustering
    import graphlab.toolkits.distances as distances
...