Closed anndan7 closed 1 year ago
Please note that the package is called leidenalg
, not leiden
. You should hence use pip install leidenalg
. Hopefully that solves your problem?
Please note that the package is called
leidenalg
, notleiden
. You should hence usepip install leidenalg
. Hopefully that solves your problem?
This doesn't solve it either sadly. It says install successfully but when I try to use Leidenalg in R, it says "Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg)"
OK, let's see what goes wrong where then. What packages have you installed, in which language (R, Python) and in what environments (base environments, virtual environments, Anaconda environments) and in what OS?
OK, let's see what goes wrong where then. What packages have you installed, in which language (R, Python) and in what environments (base environments, virtual environments, Anaconda environments) and in what OS?
Ok! I'm using RStudio for this, are you asking what all packages I have installed or what packages I'm trying to use in conjunction with leiden? I am using my base environment in RStudio, OS is Windows 11.
OK, it seems you are using Anaconda to run Python, is that correct? If so, leidenalg
is probably correctly installed in the Anaconda environment, but that environment is probably not active when you launch R. As a result, the R leiden
package is unable to find the Python leidenalg
package.
You could try to install the package from within R
using this:
library("reticulate")
py_install("leidenalg")
That way, reticulate
hopefully installs the R package in an appropriate environment.
OK, it seems you are using Anaconda to run Python, is that correct? If so,
leidenalg
is probably correctly installed in the Anaconda environment, but that environment is probably not active when you launch R. As a result, the Rleiden
package is unable to find the Pythonleidenalg
package.You could try to install the package from within
R
using this:library("reticulate") py_install("leidenalg")
That way,
reticulate
hopefully installs the R package in an appropriate environment.
I did the py_install but I am still getting the same error message
OK, sorry to hear. Perhaps you should check with the people from Seurat? They should probably have some idea as to how best solve this.
OK, sorry to hear. Perhaps you should check with the people from Seurat? They should probably have some idea as to how best solve this.
I checked with them originally and they told me to ask here because they were not sure.
I'm not entirely sure about your setup. When I try to install a new conda environment that contains both the leiden
R package and leidenalg
, it all seems to work correctly.
That is, I create a new environment called r-leiden
using conda create -n r-leiden -c conda-forge r-leiden leidenalg numpy
. After activating the environment using conda activate
r-leidenI can run
R(which should now run the R installed from
conda-forge). When importing
leidenin
Rusing
library(leiden)` you are asked to create a conda environment, which you should not, in this case, since this is already a conda environment. I then get the following output.
> library(leiden)
create conda environment (yes/no)?no
no
using environment: NA
Unable to set up conda environment r-reticulate
run in terminal:
conda init
conda create -n r-reticulate
conda environment r-reticulate installed
python modules igraph and leidenalg installed
> library(igraph)
> G <- igraph::graph.famous('Zachary')
> part <- leiden::leiden(G)
> part
[1] 2 2 2 2 4 4 4 2 1 1 4 2 2 2 1 1 4 2 1 2 1 2 1 3 3 3 1 3 3 1 1 3 1 1
Hopefully this setup works for you!
I'm not entirely sure about your setup. When I try to install a new conda environment that contains both the
leiden
R package andleidenalg
, it all seems to work correctly.That is, I create a new environment called
r-leiden
usingconda create -n r-leiden -c conda-forge r-leiden leidenalg numpy
. After activating the environment usingconda activate
r-leidenI can run
R(which should now run the R installed from
conda-forge). When importing
leidenin
Rusing
library(leiden)` you are asked to create a conda environment, which you should not, in this case, since this is already a conda environment. I then get the following output.> library(leiden) create conda environment (yes/no)?no no using environment: NA Unable to set up conda environment r-reticulate run in terminal: conda init conda create -n r-reticulate conda environment r-reticulate installed python modules igraph and leidenalg installed > library(igraph) > G <- igraph::graph.famous('Zachary') > part <- leiden::leiden(G) > part [1] 2 2 2 2 4 4 4 2 1 1 4 2 2 2 1 1 4 2 1 2 1 2 1 3 3 3 1 3 3 1 1 3 1 1
Hopefully this setup works for you!
This helps! I did the first part in the terminal and that worked, I am just confused on how to open RStudio from there.
I'm not sure if RStudio works nicely from an Anaconda environment: https://community.rstudio.com/t/using-rstudio-within-a-conda-environment/128780.
However, if you just use your system R (i.e. not installed via conda
), I'm also able to get it working. When I install leiden
using install.packages('leiden')
and then do library(leiden)
I then select "yes" to create a separate conda environment, giving the following result on my computer:
This has now setup a new conda environment r-reticulate
. The only thing then left to do is install leidenalg
(and numpy
) using
conda install -n r-reticulate -c conda-forge leidenalg numpy
after which I can again run
> G <- igraph::graph.famous('Zachary')
> leiden(G)
[1] 2 2 2 2 4 4 4 2 1 1 4 2 2 2 1 1 4 2 1 2 1 2 1 3 3 3 1 3 3 1 1 3 1 1
but now from my system R, and hence this should also work from RStudio.
Hi, I am trying to use the leiden alg (algorithm=4) with FindClusters in Seurat in Rstudio. When I try to run this, it gives the error: "Cannot find Leiden algorithm, please install through pip (e.g.
pip install leidenalg
)", even though I've donelibrary(leiden)
. When I go to my terminal to trypip install leidenalg
, I get the following process and I am not sure how to fix, thanks!