HumanCellAtlas / data-consumer-vignettes

Simple walk-throughs of interacting with the DCP as a downstream data consumer.
MIT License
17 stars 5 forks source link

Scanpy demo fais: AttributeError: module 'igraph' has no attribute 'Graph' #78

Closed chmreid closed 4 years ago

chmreid commented 4 years ago

In the May 2019 scanpy demo notebook, there is a cell with the following contents:

sc.pp.pca(adata, svd_solver='arpack')
sc.pp.neighbors(adata)
sc.tl.louvain(adata, resolution=0.15)
sc.tl.tsne(adata)
sc.tl.umap(adata)
adata.write(results_file)

However, this notebook cell fails to run (on Mac OS X 10.14) with the following error:

computing PCA with n_comps = 50
    finished (0:00:01)
computing neighbors
    using 'X_pca' with n_pcs = 50
    finished: added to `.uns['neighbors']`
    'distances', distances for each pair of neighbors
    'connectivities', weighted adjacency matrix (0:00:00)
running Louvain clustering

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-47-844736d11776> in <module>
      1 sc.pp.pca(adata, svd_solver='arpack')
      2 sc.pp.neighbors(adata)
----> 3 sc.tl.louvain(adata, resolution=0.15)
      4 sc.tl.tsne(adata)
      5 sc.tl.umap(adata)

~/codes/data-consumer-vignettes/vp/lib/python3.6/site-packages/scanpy/tools/_louvain.py in louvain(adata, resolution, random_state, restrict_to, key_added, adjacency, flavor, directed, use_weights, partition_type, partition_kwargs, copy)
    112             directed = False
    113         if not directed: logg.debug('    using the undirected graph')
--> 114         g = utils.get_igraph_from_adjacency(adjacency, directed=directed)
    115         if use_weights:
    116             weights = np.array(g.es["weight"]).astype(np.float64)

~/codes/data-consumer-vignettes/vp/lib/python3.6/site-packages/scanpy/utils.py in get_igraph_from_adjacency(adjacency, directed)
    384     if isinstance(weights, np.matrix):
    385         weights = weights.A1
--> 386     g = ig.Graph(directed=directed)
    387     g.add_vertices(adjacency.shape[0])  # this adds adjacency.shap[0] vertices
    388     g.add_edges(list(zip(sources, targets)))

AttributeError: module 'igraph' has no attribute 'Graph'

This is after running the following pip install commands (note the MACOSX_DEPLOYMENT_TARGET variable, which is necessary to successfully compile louvain on Mac OS X):

MACOSX_DEPLOYMENT_TARGET=10.9 pip3 install louvain
pip3 install jupyter loompy matplotlib numpy numpy-groupies pandas python-igraph scanpy

per the example's requirements.txt.

chmreid commented 4 years ago

I believe this issue was caused by mistakenly installing igraph or jgraph (pip install igraph / pip install jgraph) instead of python-igraph pip install python-igraph). I am not able to reproduce this error unless I install igraph or jgraph into the virtual environment.