TypeError: Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices'
报错命令:
scv.pp.moments(adata)
参考了github上的信息:
Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices' · Issue #1212 · theislab/scvelo
解决办法:

将上面代码改为:
scv.pp.moments(adata, n_neighbors=None, n_pcs=None)
最好的方法还是安装scvelo的development版本,开发者团队已经修复了这个bug
而且将参数改为n_neighbors=None, n_pcs=None后虽然不报错,但结果相差很大。
git clone https://github.com/theislab/scvelo
cd scvelo
pip install .
这里安装的时候按照官网教程会报下面的错误,所以直接用pip install就行了
git checkout --track origin/main
fatal: A branch named 'main' already exists.
或者使用下面的命令,我没试过好不好用
pip install git+https://github.com/theislab/scvelo@main
ValueError: mismatching number of index arrays for shape; got 0, expected 2
报错命令:
scv.tl.paga(adata, groups='cell_type')
解决办法:
修改源代码!
问题来了,怎么知道源代码在哪儿呢?
需要找到 scvelo 库的安装位置,代码如下:
python -c "import scvelo; print(scvelo.__file__)"
通常长这个样子:/path/to/your/python/site-packages/scvelo/init.py
scv.tl.paga 函数的实现通常在 scvelo/tools 目录下,文件名是 paga.py。
进入该目录并找到 paga.py 文件,把下面的代码
if len(edges) > 0:
return csr_matrix((weights, zip(*edges)), shape=shape)
改成下面这样子:
rows, cols = zip(*edges)
if len(edges) > 0:
return csr_matrix((weights, (rows, cols)), shape=shape)
当然,github上也有人用别的方法,比如:
I install scipy==1.11.4 to avoid the self._check() error, and solve this problem.