TheoreticalEcology / s-jSDM

Scalable joint species distribution modeling
https://cran.r-project.org/web/packages/sjSDM/index.html
GNU General Public License v3.0
68 stars 14 forks source link

PyTorch not installed #132

Closed yang963469904 closed 12 months ago

yang963469904 commented 1 year ago

Thank you for providing the package, but I encountered difficulties during installation. The automatic installation display package cannot be used, so I manually downloaded minniconda3 to install pytorch. Display installation success in Python, but cannot be used in r。

import torch print(torch.version.cuda) 11.8

── Attaching sjSDM ───────────────────────────────────────────────────────────────────────────── 1.0.5 ── ✖ torch ✖ torch_optimizer ✖ pyro ✖ madgrad

Torch or other dependencies not found:

  1. Use install_sjSDM() to install Pytorch and conda automatically
  2. Installation trouble shooting guide: ?installation_help
  3. If 1) and 2) did not help, please create an issue on https://github.com/TheoreticalEcology/s-jSDM/issues (see ?install_diagnostic) Error: PyTorch not installed

install_diagnostic() name python 1 pythonProject1 C:\Users\86133\.conda\envs\pythonProject1/python.exe 2 r-sjsdm C:\Users\86133\.conda\envs\r-sjsdm/python.exe 3 base I:\miniconda3/python.exe

ENV: pythonProject1

torch: packages in environment at C:\Users\86133.conda\envs\pythonProject1:

Name Version Build Channel

numpy: packages in environment at C:\Users\86133.conda\envs\pythonProject1:

Name Version Build Channel

ENV: r-sjsdm

torch: packages in environment at C:\Users\86133.conda\envs\r-sjsdm:

Name Version Build Channel pytorch-ranger 0.1.1 pypi_0 pypi torch 2.0.1+cu118 pypi_0 pypi torch-optimizer 0.3.0 pypi_0 pypi torchaudio 2.0.2+cu118 pypi_0 pypi torchvision 0.15.2+cu118 pypi_0 pypi

numpy: packages in environment at C:\Users\86133.conda\envs\r-sjsdm:

Name Version Build Channel

ENV: base

torch: packages in environment at I:\miniconda3:

Name Version Build Channel

numpy: packages in environment at I:\miniconda3:

Name Version Build Channel

python: C:/Users/86133/.conda/envs/r-sjsdm/python.exe libpython: C:/Users/86133/.conda/envs/r-sjsdm/python39.dll pythonhome: C:/Users/86133/.conda/envs/r-sjsdm version: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)] Architecture: 64bit numpy: C:/Users/86133/AppData/Roaming/Python/Python39/site-packages/numpy numpy_version: 1.26.0 torch: C:\Users\86133\CONDA~1\envs\r-sjsdm\lib\site-packages\torch__init__.p

NOTE: Python version was forced by use_python() function

 active environment : None
   user config file : C:\Users\86133\.condarc

populated config files : C:\Users\86133.condarc conda version : 23.5.2 conda-build version : not installed python version : 3.11.4.final.0 virtual packages : __archspec=1=x86_64 cuda=12.2=0 win=0=0 base environment : I:\miniconda3 (read only) conda av data dir : I:\miniconda3\etc\conda conda av metadata url : None channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : I:\miniconda3\pkgs C:\Users\86133.conda\pkgs C:\Users\86133\AppData\Local\conda\conda\pkgs envs directories : C:\Users\86133.conda\envs I:\miniconda3\envs C:\Users\86133\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/23.5.2 requests/2.29.0 CPython/3.11.4 Windows/10 Windows/10.0.22000 administrator : False netrc file : None offline mode : False

MaximilianPi commented 1 year ago

Hi @yang963469904,

it seems that you have several conda installations that interfere with each other: C:\Users\86133\CONDA~1 C:/Users/86133/.conda

I would suggest that you delete one of the two (by deleting the folders), then run in R:

library(reticulate)
reticulate::conda_remove("r-reticulate")
reticulate::conda_remove("r-sjSDM")

reticulate::conda_create(envname = "r-sjsdm", python_version = "3.9")
# CPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "cpuonly", "-c", "pytorch"))
# GPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "pytorch-cuda=11.7", "-c", "pytorch", "-c" ,"nvidia"))

reticulate::conda_install(envname = "r-sjsdm",
                          packages = c("pyro-ppl", "torch_optimizer", "madgrad", "tqdm"), pip = TRUE)

Restart Rstudio and load sjSDM.

yang963469904 commented 1 year ago

Thank you for your reply. I currently only have one mini conda installed, and I tried to remove the path C:\Users\86133\CONDA~1, but I couldn't find it on the C drive. I'm wondering if the reason why the previously installed Conda was not completely removed? But I can't find a solution at the moment.

The path I saw in Python is

import torch print(torch.file) C:\Users\86133.conda\envs\r-sjsdm\lib\site-packages\torch__init__.py

But the path at is > install_diagnostic() torch: C:\Users\86133\CONDA~1\envs\r-sjsdm\lib\site-packages\torch__init__.p I'm wondering if it's a problem here.

MaximilianPi commented 1 year ago

hm, let's ignore that for now. Have you run the following code?:

library(reticulate)
reticulate::conda_remove("r-sjSDM")

reticulate::conda_create(envname = "r-sjsdm", python_version = "3.9")
# CPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "cpuonly", "-c", "pytorch"))
# GPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "pytorch-cuda=11.7", "-c", "pytorch", "-c" ,"nvidia"))

reticulate::conda_install(envname = "r-sjsdm",
                          packages = c("pyro-ppl", "torch_optimizer", "madgrad", "tqdm"), pip = TRUE)
yang963469904 commented 1 year ago

I have tried the code you gave me several times, but the results are all the same.

MaximilianPi commented 1 year ago

That's weird, sorry, this might be a stupid question, but you have an NVIDIA GPU, right? Because you have the cuda/gpu torch version installed.

yang963469904 commented 1 year ago

Yes, I am using a laptop, and my GPU is NVIDIA GeForce MX450

MaximilianPi commented 1 year ago

Just for the record, could you please reinstall everything with the cpu pytorch version?:

library(reticulate)
reticulate::conda_remove("r-sjSDM")

reticulate::conda_create(envname = "r-sjsdm", python_version = "3.9")
# CPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "cpuonly", "-c", "pytorch"))

reticulate::conda_install(envname = "r-sjsdm",
                          packages = c("pyro-ppl", "torch_optimizer", "madgrad", "tqdm"), pip = TRUE)
yang963469904 commented 1 year ago

Okay, I reinstalled it, but I still can't use SJSDM

install_diagnostic() name python 1 r-sjsdm C:\Users\86133\.conda\envs\r-sjsdm/python.exe 2 base I:\miniconda/python.exe

ENV: r-sjsdm

torch: packages in environment at C:\Users\86133.conda\envs\r-sjsdm:

Name Version Build Channel pytorch 2.1.0 py3.9_cpu_0 pytorch pytorch-mutex 1.0 cpu pytorch pytorch-ranger 0.1.1 pypi_0 pypi torch-optimizer 0.3.0 pypi_0 pypi torchaudio 2.1.0 py39_cpu pytorch torchvision 0.16.0 py39_cpu pytorch

numpy: packages in environment at C:\Users\86133.conda\envs\r-sjsdm:

Name Version Build Channel numpy 1.26.0 py39hddb5d58_0 conda-forge

ENV: base

torch: packages in environment at I:\miniconda:

Name Version Build Channel

numpy: packages in environment at I:\miniconda:

Name Version Build Channel

python: C:/Users/86133/.conda/envs/r-sjsdm/python.exe libpython: C:/Users/86133/.conda/envs/r-sjsdm/python39.dll pythonhome: C:/Users/86133/.conda/envs/r-sjsdm version: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)] Architecture: 64bit numpy: C:/Users/86133/AppData/Roaming/Python/Python39/site-packages/numpy numpy_version: 1.26.0 torch: C:\Users\86133\CONDA~1\envs\r-sjsdm\lib\site-packages\torch__init__.p

NOTE: Python version was forced by use_python() function

 active environment : None
   user config file : C:\Users\86133\.condarc

populated config files : conda version : 23.5.2 conda-build version : not installed python version : 3.11.4.final.0 virtual packages : __archspec=1=x86_64 cuda=12.2=0 win=0=0 base environment : I:\miniconda (read only) conda av data dir : I:\miniconda\etc\conda conda av metadata url : None channel URLs : https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : I:\miniconda\pkgs C:\Users\86133.conda\pkgs C:\Users\86133\AppData\Local\conda\conda\pkgs envs directories : C:\Users\86133.conda\envs I:\miniconda\envs C:\Users\86133\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/23.5.2 requests/2.29.0 CPython/3.11.4 Windows/10 Windows/10.0.22000 administrator : False netrc file : None offline mode : False

MaximilianPi commented 1 year ago

Ok, maybe we can delete the directory from within R:

unlink("C:\Users\86133\CONDA~1",recursive = TRUE)

Afterwards restart RStudio and load sjSDM

yang963469904 commented 1 year ago

After i delete the directory, I found that my r-sjsdm environment has also been deleted.

kendrag-csu commented 1 year ago

Hello,

Thank you for the package! Unfortunately I'm having the same issue as yang. I've followed the suggestions above, and still get the following error each time.

`> library(sjSDM) ── Attaching sjSDM ──────────────────────────────────────────── 1.0.5 ── ✖ torch ✖ torch_optimizer ✖ pyro ✖ madgrad

Torch or other dependencies not found:

  1. Use install_sjSDM() to install Pytorch and conda automatically
  2. Installation trouble shooting guide: ?installation_help
  3. If 1) and 2) did not help, please create an issue on https://github.com/TheoreticalEcology/s-jSDM/issues (see ?install_diagnostic) Warning message: package ‘sjSDM’ was built under R version 4.2.3 `
MaximilianPi commented 1 year ago

Hi @kendrag-csu, @yang963469904,

I think I found something, let's try the latest pytorch and support python version:

library(reticulate)
reticulate::conda_remove("r-sjSDM")

reticulate::conda_create(envname = "r-sjsdm", python_version = "3.11")
# CPU Version:
reticulate::conda_install(envname = "r-sjsdm", 
                          packages =c("pytorch", "torchvision", "torchaudio", "cpuonly", "-c", "pytorch"))

reticulate::conda_install(envname = "r-sjsdm",
                          packages = c("pyro-ppl", "torch_optimizer", "madgrad", "tqdm"), pip = TRUE)
yang963469904 commented 12 months ago

Thanks very much for your reply. After I reinstalled the system, the problem was solved.