Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UMAP installed but not recognized #1020

Closed
cstill1992 opened this issue Dec 18, 2018 · 27 comments
Closed

UMAP installed but not recognized #1020

cstill1992 opened this issue Dec 18, 2018 · 27 comments

Comments

@cstill1992
Copy link

cstill1992 commented Dec 18, 2018

Hi, I'm excited to use the new integration with UMAP but I can't get it to work. Below is the R code and verification that it is installed.

> scRNAseq.integrated <- RunUMAP(object = scRNAseq.integrated, reduction = "pca", dims = 1:30)
Error in RunUMAP.default(object = data.use, assay = assay, n.neighbors = n.neighbors,  : 
  Cannot find UMAP, please install through pip (e.g. pip install umap-learn).
DN0a22b768:~ cstill$ pip show umap-learn
Name: umap-learn
Version: 0.3.7
Summary: Uniform Manifold Approximation and Projection
Home-page: http://github.com/lmcinnes/umap
Author: None
Author-email: None
License: BSD
Location: /Users/cstill/anaconda3/lib/python3.7/site-packages
Requires: scikit-learn, numba, scipy, numpy
Required-by: 
DN0a22b768:~ cstill$ 
>>> sam.run_umap()
array([[16.360878 ,  6.602775 ],
       [15.218763 ,  6.808421 ],
       [19.056177 ,  8.954225 ],
       ...,
       [22.249752 ,  2.8561206],
       [18.007689 , 25.26965  ],
       [19.846735 , 18.987228 ]], dtype=float32)
@sameet
Copy link

sameet commented Dec 19, 2018

I had the same issue. But you can save.image(); q(); y. Then do pip install umap-learn. Restart the R session, and it works.

@mojaveazure
Copy link
Member

Hi @cstill1992,

What happens if you install UMAP using the Pip/Python installation that came with your Mac? We've noticed that reticulate doesn't see Anaconda-installed Python modules, so we recommend not using Anaconda.

@mojaveazure mojaveazure added the more-information-needed We need more information before this can be addressed label Jan 3, 2019
@satijalab
Copy link
Collaborator

Closing this issue as both suggested solutions (not using anaconda, and restarting R) should be sufficient for reticulate to detect UMAP

@samuel-marsh
Copy link
Collaborator

samuel-marsh commented Jan 31, 2019

@satijalab @mojaveazure
Just wanted to send fyi. Still new to all of this but after some playing around it appears that reticulate can function with Anaconda but it seems to have trouble if you create environments and install packages directly through Anaconda. However, if you install packages through reticulate in R then it creates environment and works with no issues for me (at least on Mac OS X).
Following auto creates Anaconda environment "r-reticulate" and installs umap and dependencies.
library(reticulate)
py_install("umap-learn")

So if there is a need to use Anaconda or that is what users have installed appears that this works to solve the issue.

Thanks for all you do with Seurat!

@Abghaith
Copy link

Hi, I have the same issue and I tried all the above solution and doesn't work.
I am using Seurat v3 on Centos 7.

@iiiir
Copy link

iiiir commented Apr 17, 2019

I am using Domino system and both solution did not work for me. Still have the "could not find UMAP" error.
try #1
pip install umap-learn
try #2
library(reticulate)
py_install("umap-learn")

I cannot restart the R session -- every time I shut down the session it will start a new EC2.
Any suggestion?

Thanks,
Shuoguo

@cstill1992
Copy link
Author

Hi guys, sorry for getting away from this for a bit. So neither of the above solutions really worked for me and I eventually just did conda install -c conda-forge umap-learn (as shown here: https://umap-learn.readthedocs.io/en/latest/) and everything started working. Not sure why this worked though. Might be worth giving a try if you still haven't gotten it working.

@no-response no-response bot removed the more-information-needed We need more information before this can be addressed label Apr 18, 2019
@no-response no-response bot reopened this Apr 18, 2019
@Abghaith
Copy link

Hi, I found the solution, so umap-learn should be installed using python v3 and pip v3
so before installing umap you should upgrade the pipe to v3.
Best.

@iiiir
Copy link

iiiir commented Apr 18, 2019

in my case pip3 install umap-learn did the trick. thanks @Abghaith !!

@iiiir
Copy link

iiiir commented Apr 24, 2019

just figured out in a new EC2 instance that after install i also need to restart r session to get it work:.rs.restartR()

@cemalley
Copy link

I had to add the location of my python 3 in the R session.

library(reticulate)
use_python("/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/")

@arararararararar8
Copy link

Hello. Can someone give me the final codes that you used on both anaconda and r for umap installation? Please give the order also.

@andrewwbutler andrewwbutler mentioned this issue May 2, 2019
@s-andrews
Copy link

Another fix which worked in my case and which I haven't seen in previous comments.

In my case the problem was that reticulate wasn't able to find my python install, so nothing worked, but the error was that the umap package was missing (which wasn't the issue).

The check for this is:

library(reticulate)
py_config()

You'll either get something which says which version of python has been found, or in my case it produced:

> py_config()
Error in initialize_python(required_module, use_environment) : 
  Installation of Python not found, Python bindings not loaded.

If I then specified the location of python by running use_python then it started working.

> use_python("C:/Program Files/Python37/python.exe")
> py_config()
python:         C:/Program Files/Python37/python.exe
libpython:      C:/Program Files/Python37/python37.dll
pythonhome:     C:\PROGRA~1\Python37
version:        3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Users\Training9\AppData\Roaming\Python\Python37\site-packages\numpy
numpy_version:  1.16.4

After the python was discovered then RunUMAP also started to work.

@hmassalha
Copy link

Hi,
The umap-learn package is installed ...
> py_config() python: /apps/RH7U2/gnu/anaconda/5.2.0/python/3.6/bin/python libpython: /apps/RH7U2/gnu/anaconda/5.2.0/python/3.6/lib/libpython3.6m.so pythonhome: /apps/RH7U2/gnu/anaconda/5.2.0/python/3.6:/apps/RH7U2/gnu/anaconda/5.2.0/python/3.6 version: 3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0] numpy: [NOT FOUND] umap: /home/labs/shalev/hassanm/.local/lib/python3.6/site-packages/umap

but still, I can't run the UMAP Seurat command!
human.combined <- RunUMAP(human.combined, reduction = "pca", dims = 1:30) Error in RunUMAP.default(object = data.use, assay = assay, n.neighbors = n.neighbors, : Cannot find UMAP, please install through pip (e.g. pip install umap-learn).

Any suggestions...

Thanks, HM

@dkcoxie
Copy link

dkcoxie commented Jul 8, 2019

HM, it looks like your umap install is in in a local path instead of installed with conda. If you have multiple python installs, try use_python("/home/labs/shalev/hassanm/.local/lib/python3.6/") to allow R to recognize where it should be looking for packages as outlined prior in this thread.

@YiweiNiu
Copy link

@s-andrews's answer helped but not worked in my case.

I am working in Rstudio server. Using use_python cannot change the Python used by R. See the discussions here.

> library(reticulate)
> py_config()
python:         /usr/bin/python
libpython:      /usr/lib64/libpython2.7.so.1.0
pythonhome:     /usr:/usr
version:        2.7.5 (default, Aug  4 2017, 00:39:18)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
numpy:          /T02Data/niuyw/.local/lib/python2.7/site-packages/numpy
numpy_version:  1.16.4
> use_python('/T02Data/niuyw/software/anaconda3/bin/python')
> py_config()
python:         /usr/bin/python
libpython:      /usr/lib64/libpython2.7.so.1.0
pythonhome:     /usr:/usr
version:        2.7.5 (default, Aug  4 2017, 00:39:18)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
numpy:          /T02Data/niuyw/.local/lib/python2.7/site-packages/numpy
numpy_version:  1.16.4

And the method below worked for me.

Install umap under the Python used by R.

# install pip
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ /usr/bin/python get-pip.py --user

# install umap
$ .local/bin/pip install umap-learn --user

I also tried to change RETICULATE_PYTHON in .Renviron to the Python I want to use. This way changed the Python used by reticulate indeed but I still got the error 'Cannot find UMAP', though I had installed it through pip.

$ cat .Renviron
RETICULATE_PYTHON=~/software/anaconda3/bin/python

Hope this would be helpful for situations like me.

@QiliangLai
Copy link

just figured out in a new EC2 instance that after install i also need to restart r session to get it work:.rs.restartR()

Thanks. This worked

@lloydm7
Copy link

lloydm7 commented Aug 16, 2019

Hi I'm new to seurat and I've tried the above options but still having trouble. This is my code:

install.packages("reticulate")
library(reticulate)
reticulate::py_install(packages ='umap-learn')
GIST <- RunUMAP(GIST, dims = 1:11)

Error in RunUMAP(GIST, dims = 1:11) : could not find function "RunUMAP"

I've got the latest version of anaconda. I'm on windows 64-bit.

Any suggestions would be very much appreciated :)

@ldorozco
Copy link

All the above also helped me to untangle the problems I was having.
I did the local install, and ensured R could see my python (which it was not before). I was still having problems, then I realized that if I started a python3 shell, even then doing "import umap" did not work. The final error was that python3 was looking for a newer version of scipy that was not installed. Upgrade scipy and try again.

python3 -m pip install scipy --user --upgrade

I realize that Seurat now using "uwot", but that won't solve the umap issue if you are doing:

RunUMAP(obj, umap.method='umap-learn')

@rachel662
Copy link

Hi there,

I keep getting this issue when trying to use umap on my Seurat object in R
Error: Cannot find 'umap' in this Seurat object

I have tried renaming and reinstalling umap-learn with reticulate::py_install(packages = 'umap-learn')
however this isn't working, I am using python version 3.8, could that be the problem?

would be very grateful if anyone could help me with this issue!
Rachel

@yuxiaokang-source
Copy link

I have meet the same problem。 I use "pip3 install umap-learn" in the terminal of Rstudio, then I restart the Rstudio, It worked

@AnnaAMonaco
Copy link

Hi, I am also encountering the same issue and haven't found a solution.

I try running the following over four Seurat objects:

> set.seed(763)
> samples <- list(fld24,hld24,fld30.5,hld30.5)
> for (i in 1:length(samples)) {
  samples[[i]] <- RunUMAP(samples[[i]], reduction = "pca", dims = 1:40, nn.name = "weighted.nn")
  samples[[i]] <- FindNeighbors(samples[[i]], reduction = "pca", dims = 1:40)
  samples[[i]] <- FindClusters(samples[[i]], resolution = 0.5)
}

All runs fine, then if I try to plot the UMAP:

> DimPlot(fld24, reduction = "umap", label = TRUE, repel = TRUE)
Error: Cannot find 'umap' in this Seurat object

And indeed none of them have the reduction in the meta data

> fld24@meta.data$
fld24@meta.data$orig.ident    fld24@meta.data$nFeature_RNA  fld24@meta.data$percent.rbp
fld24@meta.data$nCount_RNA    fld24@meta.data$percent.mt

I tried some of the above solutions and somehow it worked once, but when I had to close and restart a new R session they no longer worked -- even when I repeated them. This is the one that worked the first time:

library(reticulate)
py_config()

And if I try it now that it doesn't work again I get the same output as when it did

> library(reticulate)
> py_config()
python:         /home/amonaco/.local/share/r-miniconda/envs/r-reticulate/bin/python
libpython:      /home/amonaco/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.8.so
pythonhome:     /home/amonaco/.local/share/r-miniconda/envs/r-reticulate:/home/amonaco/.local/share/r-miniconda/envs/r-reticulate
version:        3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 16:01:55)  [GCC 11.3.0]
numpy:          /home/amonaco/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/numpy
numpy_version:  1.23.5

I also tried the pip3 install umap-learn solution but it didn't work for me.

> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: MarIuX64 2.0 GNU/Linux
  
Matrix products: default
BLAS:   /pkg/R-4.2.2-0/lib/R/lib/libRblas.so
LAPACK: /pkg/R-4.2.2-0/lib/R/lib/libRlapack.so
  
locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C
  
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
  
other attached packages:
[1] reticulate_1.28    ggplot2_3.4.0      patchwork_1.1.2    SeuratObject_4.1.3
[5] Seurat_4.3.0   

@cemalley
Copy link

> DimPlot(fld24, reduction = "umap", label = TRUE, repel = TRUE)
Error: Cannot find 'umap' in this Seurat object

Hi @AnnaAMonaco this error means UMAP was not run and/or not saved in the seurat object. I see you're having trouble installing it on your machine. I believe there is also a R-based version of UMAP you can install. Can you try install.packages('umap') ?

@samuel-marsh
Copy link
Collaborator

Hi @AnnaAMonaco

@cemalley is right that there is issue with the UMAP saving to the object. What happens if you just run the code in solo not in for loop?

In terms of umap-learn that is not necessary unless you want to use the python version. Since Seurat 3.1.0 the R native uwot package is the default method for running umap unless you specifically specify otherwise during the RunUMAP call.

Best,
Sam

@AnnaAMonaco
Copy link

@cemalley that worked, thanks so much!

@Jokendo-collab
Copy link

py_install("umap-learn")

This also worked for me

@MartaBenegas
Copy link

@mojaveazure

Hi all! I've been through all the options mentioned here but I haven't found a solution for my case.

I've installed python3 and umap-learn through pip3 in a Docker:

RUN apt update && apt install -y \
          python3 \
          python3-pip

RUN pip3 install umap-learn

I've forced the RETICULATE_PYTHON to be python3.8 by specifying it on the .Renviron. Since I was not sure which one was the correct place to put it, I put the .Renviron in both the / and the ~ folders.

RUN echo "RETICULATE_PYTHON=/usr/bin/python3.8" > ~/.Renviron
RUN echo "RETICULATE_PYTHON=/usr/bin/python3.8" > /.Renviron

The py_config() shows that the reticulate points to python3.8:

> library(reticulate) 
> py_config()
python:         /usr/bin/python3.8
libpython:      /usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so
pythonhome:     //usr://usr
version:        3.8.10 (default, May 26 2023, 14:05:08)  [GCC 9.4.0]
numpy:          /usr/local/lib/python3.8/dist-packages/numpy
numpy_version:  1.21.0

NOTE: Python version was forced by RETICULATE_PYTHON

Which is where the umap-learn is inside the docker:

root@95c3f800eccb:~# pip3 show umap-learn
Name: umap-learn
Version: 0.5.4
Summary: Uniform Manifold Approximation and Projection
Home-page: http://github.com/lmcinnes/umap
Author: None
Author-email: None
License: BSD
Location: /usr/local/lib/python3.8/dist-packages
Requires: tqdm, numpy, scikit-learn, numba, tbb, scipy, pynndescent
Required-by: 

I don't know if it matters, but I'm running an R script with the Seurat code from a Python script. At the beginning of the Python script I specified #!/usr/bin/python3.8

Still, the following error appears:

Error in RunUMAP.default(object = data.use, reduction.model = reduction.model,  :
Cannot find UMAP, please install through pip (e.g. pip install umap-learn).
Calls: RunUMAP -> RunUMAP.Seurat -> RunUMAP -> RunUMAP.default

I'm running umap like this:

s.object <- RunUMAP(s.object, dims=1:15, umap.method="umap-learn", reduction="PCA")

It seems that everything matches, why it is still unable to find the umap-learn? Any help will be greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests