首先需要在R中下载并读取reticulate包,该包提供了一系列R-Python的交互式命令
由于之前在电脑中通过三个方式安装了Python:
直接安装 Python 3.10
安装Anaconda,携带3.9
安装 Miniconda,又是另外一个版本的Python
版本各不相同,造成了在Rstudio 中配置 Python 环境出现各种各样的问题,Rstudio 默认的Python路径就是通过第一种方法安装的 Python 3.10,根本无法切换想要使用的包含"umap-learn"包的Python版本。
尝试了多个方法,最后还是首先在 Python 3.10 中安装 "umap-learn" package,方法如下
window 系统进入 cmd 命令窗口
python --version # 检查系统默认 python 版本,结果显示是直装的 Python 3.10
pip install umap-learn # pip 命令安装包
library(reticulate) # 进入Rstudio,加载reticulate包
py_available() # 显示 False
py_config() # 默认配置 Python,主要是因为我的Rstudio改不了
py_available() # 显示 True
py_module_available("umap-learn") # 仍然显示 False,但是可以用了,就很神奇
或者尝试运行 py_install("umap-learn"),重新安装一遍umap-learn