#remotes::install_github(“rstudio/reticulate”)
library(reticulate)
use_condaenv(‘C:/Users/yll/AppData/Local/r-miniconda/envs/giotto_env/’)
‘’’
conda_install(envname = “giotto_env” , packages=c(
“pandas”, “python-igraph”, “networkx”, “python-louvain”, “leidenalg”, “scikit-learn”
), forge = TRUE, conda = “auto”, python_version = NULL)
conda_install(envname = “giotto_env”,packages=“smfishHmrf”,
forge = TRUE)
conda_install(envname = “giotto_env”,packages=“dataclasses”,
forge = TRUE)
‘’’
Sys.setenv(RETICULATE_PYTHON = “C:/Users/yll/AppData/Local/r-miniconda/envs/giotto_env/python.exe”)
library(reticulate)
py_config()
reticulate::py_config()
#https://zhuanlan.zhihu.com/p/164507492
#1、配置 Python 环境
#有四种配置方式,具体查看官方教程
use_python()
use_condaenv()
use_virtualenv()
use_miniconda()
py_config()
#miniconda 环境
#如果不太懂如何配置 Python 环境,推荐一行代码安装 miniconda 环境,之后便可在 R 中执行 Python
install_miniconda()
miniconda_path()
miniconda_update()
#2、在 R 中调用 Python 模块
os <- import(“os”)
os$listdir("./")
sns <- import(“seaborn”)
tips <- sns$load_dataset(“tips”)
print(head(tips))
#在 R 中安装 python 模块
py_install(“seaborn”, pip = T)
py_module_available(“seaborn”)
#6、R 中运行 Python 代码片段
py_run_string(“a = [1, 2, 3]; b = [2, 3, 4]; c = list(zip(a, b))”)
a
Sys.which(“python”)
Sys.getenv()
reticulate::use_condaenv(giotto_env)
use_condaenv(“C:/Users/yll/AppData/Local/r-miniconda/envs/giotto_env”)
reticulate::import(“leidenalg”)
reticulate::import(“pillow”)
reticulate::import(“pandas”)
py_config()#安装的python版本环境查看,显示anaconda和numpy的详细信息。
py_available()#[1] TRUE #检查您的系统是否安装过Python
py_module_available(“leidenalg”)#检查“pandas”是否安装
#查看python路径
Sys.which(“python”)
#“D:\ProgramData\Anaconda21\python.exe”
##这里我使用的conda,所以指定conda中的python
#查看模块是否安装成功
py_module_available(c(“pandas”,“leidenalg”))
#查看是否安装python
py_available(“pandas”)
py_available(“leidenalg”)
#[1] TRUE
###########
#################################33333
#https://www.jianshu.com/p/06dbd8dcc198
getwd()
path=“G:/silicosis/sicosis/gitto/”
setwd(path)
#查看python路径
Sys.which(“python”)
#“D:\ProgramData\Anaconda21\python.exe”
##这里我使用的conda,所以指定conda中的python
library(reticulate)
#创建conda环境
conda_create(envname=‘myr-reticulate’,conda = “auto”,packages = “python”)
##envname指定创建环境的名称,conda指定conda可执行文件的路径,packages指定要安装或删除的包名称
use_condaenv(“myr-reticulate”)
use_condaenv(‘C:/Users/yll/AppData/Local/r-miniconda/envs/giotto_env/’)
conda_install(envname = “giotto_env” , packages=c(
“pandas”, “python-igraph”, “networkx”, “python-louvain”, “leidenalg”, “scikit-learn”
), forge = TRUE, conda = “auto”, python_version = NULL)
conda_install(envname = “giotto_env”,packages=“smfishHmrf”,
forge = TRUE)
conda_install(envname = “giotto_env”,packages=“dataclasses”,
forge = TRUE)
#指定python路径
use_python(“C:\Users\yll\AppData\Local\r-miniconda\envs\myr-reticulate\python.exe”,
required = T)
#指定环境路径
#use_virtualenv(“C:\Users\yll\AppData\Local\r-miniconda\envs\myr-reticulate\”,
#安装模块 使用python安装
#py_install(“smfishHmrf”, envname = “myr-reticulate”, method=“auto”)
conda_install(envname = “myr-reticulate” , packages=c(
“pandas”, “python-igraph”, “networkx”, “python-louvain”, “leidenalg”, “scikit-learn”
), forge = TRUE, conda = “auto”, python_version = NULL)
conda_install(envname = “myr-reticulate”,packages=“smfishHmrf”,
forge = TRUE)
##使用conda安装,也可也使用pip参数指定pip安装,还可以指定python版本,conda环境名称,路径以及其他功能
#查看模块是否安装成功
py_module_available(“leidenalg”)
py_module_available(“pillow”)
##返回T or F
py_available(“pandas”)
py_available(“leidenalg”)
conda_list()
use_condaenv(“myr-reticulate”)
package_version(“reticulate”)
find.package(“reticulate”)
sessionInfo(“reticulate”)
####查看r的版本
r --version
####查看所有安装包的版本
packinfo <- installed.packages(fields = c(“Package”, “Version”))
packinfo[,c(“Package”, “Version”)]
####查看r包本地的下载路径
.libPaths()
remotes::install_github(“rstudio/reticulate”)