trying to run louvain clustering but got the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-22-fe1390cdc24a> in <module>
----> 1 sc.tl.louvain(adata, resolution=1.0)
~/miniconda3/envs/scrna/lib/python3.7/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)
136 partition_kwargs["weights"] = weights
137 logg.info(' using the "louvain" package of Traag (2017)')
--> 138 louvain.set_rng_seed(random_state)
139 part = louvain.find_partition(
140 g, partition_type,
~/miniconda3/envs/scrna/lib/python3.7/site-packages/louvain/functions.py in set_rng_seed(seed)
23 def set_rng_seed(seed):
24 """ Set seed for internal random number generator. """
---> 25 _c_louvain._set_rng_seed(seed)
26
27 def find_partition(graph, partition_type, initial_membership=None, weights=None, **kwargs):
AttributeError: module 'louvain._c_louvain' has no attribute '_set_rng_seed'
sc.tl.louvain(adata, resolution=1.0)
Python 3.7
scanpy==1.4.6 anndata==0.7.1 umap==0.4.2 numpy==1.18.3 scipy==1.4.1 pandas==1.0.3 scikit-learn==0.22.2.post1 statsmodels==0.11.1 python-igraph==0.8.2 louvain==0.6.2
This looks like an bug in the most recent release of louvain. Try downgrading?
I would also recommend using leiden clustering instead.
Fixed in 7c65221c5a9a4c1ccf924cc0ff4dbd505116c8ec
FYI, it appears that this bug remains in louvain version 0.7
In [1]: import numpy as np
...: import scanpy as sc
...:
...: adata = sc.AnnData(np.random.normal(size=(100,3)))
...:
...: sc.pp.neighbors(adata)
...: sc.tl.louvain(adata)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-3505d1878068> in <module>
5
6 sc.pp.neighbors(adata)
----> 7 sc.tl.louvain(adata)
~/.local/lib/python3.7/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)
136 partition_kwargs["weights"] = weights
137 logg.info(' using the "louvain" package of Traag (2017)')
--> 138 louvain.set_rng_seed(random_state)
139 part = louvain.find_partition(
140 g, partition_type,
AttributeError: module 'louvain' has no attribute 'set_rng_seed'
In [2]: import louvain
In [3]: louvain.__version__
Out[3]: '0.7.0'
Hello,
I am having the same issue, here is my code and error :
sc.tl.louvain(adata,resolution=0.4)
running Louvain clustering
using the "louvain" package of Traag (2017)
Traceback (most recent call last):
File "
File "/home/Morgane/anaconda3/lib/python3.7/site-packages/scanpy/tools/_louvain.py", line 138, in louvain
louvain.set_rng_seed(random_state)
AttributeError: module 'louvain' has no attribute 'set_rng_seed'
I am using Louvain version 0.7.0
Did you fix this issue in that version?
thanks for your help,
Morgane
The API for setting the random seed changed in the recent release (v0.7) of louvain, this is fixed on master, which should see a release soon.
If anyone is stuck waiting for the new release, you can edit your .../lib/python3.7/site-packages/scanpy/tools/_louvain.py with these changes:
Add: partition_kwargs["seed"] = random_state
Remove: louvain.set_rng_seed(random_state)
From:
https://github.com/theislab/scanpy/pull/1197/commits/b54d67b9d6b41269c1612df0242210d1279ede85
If anyone is stuck waiting for the new release, you can edit your
.../lib/python3.7/site-packages/scanpy/tools/_louvain.pywith these changes:Add:
partition_kwargs["seed"] = random_state
Remove:louvain.set_rng_seed(random_state)From:
b54d67b
Thankx this worked
Install old louvain package will solve the problem: pip install louvain==0.6.1
Most helpful comment
If anyone is stuck waiting for the new release, you can edit your
.../lib/python3.7/site-packages/scanpy/tools/_louvain.pywith these changes:Add:
partition_kwargs["seed"] = random_stateRemove:
louvain.set_rng_seed(random_state)From:
https://github.com/theislab/scanpy/pull/1197/commits/b54d67b9d6b41269c1612df0242210d1279ede85