问题展开
突然发现,Pycharm上挂着R去运行,这个IDE其实比我们在远程服务器启动Jupyter Notebook 然后挂到隧道上的方式 要稳定和快速得多
因此自己想尝试配一下 在远程服务器上的conda环境里面的 R 能否在本地的Pycharm Professional上直接使用
踩了一些坑 留给大家记录。
插件下载
下载第一步 先下载插件 在 Pycharm-》File-》Setting-》Plugin 内搜索 插件即可
下载完成后 ,pycharm Professional 创建R project的选项就可以显示了
激活远程conda环境 架设管道 配置
-
登录服务器,conda activate(一定要切到对应的服务器节点)
-
架设管道,保证本地的Localhost可以访问
-
架设成功后 测试环境是否OK,尝试创建一个新的 R project
然后发现 需要输入Base Interpreter 只需要输入
丢失Rwrapper文件!!!
很有可能在上述步骤完成后报错 ,说丢失了Rwrapper文件
这个的原因呢,其实是因为 我们安装的Plugin R插件 内默认的R环境 是本地R环境 类似于/home/XXX名字这样子,会在这下面去找你的 /bin /lib等等
但是其实你是在conda环境里面 但是插件是无法智能追踪这个Conda 的R环境的 如果要解决这个问题嘛
可以试着去找一下这个R文件
尝试解决方案
找了下 发现好像把
XXX/conda/R环境名称/lib/R/lib/libR.so的这个libR.so文件直接复制过去?或者 做一个软连接
都是不行的
然后发现一个新的方法,想办法在插件启动的时候 让插件自己去找这个环境
这个帖子可以参考
我们将 自己Pycharm Project里面的 Plugin 里面的这个文件拎出来
然后记事本打开 然后替换为
# Rkernel is an execution kernel for R interpreter
# Copyright (C) 2019 JetBrains s.r.o.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https:#www.gnu.org/licenses/>.
getLDLibraryPath <- function() {
sysinf <- Sys.info()
if (sysinf['sysname'] == "Darwin") Sys.getenv("DYLD_FALLBACK_LIBRARY_PATH")
else if (tolower(sysinf['sysname']) == "linux") {
if(Sys.getenv("LDLIBRARY_PATH") == "") {
sessinf <- sessionInfo()
interpreter_lib_dir <- dirname(sessinf$BLAS)
paste(interpreter_lib_dir, paste0(interpreter_lib_dir, "/R/lib"), sep = ":")
} else {
Sys.getenv("LDLIBRARY_PATH")
}
}
else ""
}
cat(">>>RPLUGIN>>>")
cat(R.home(), R.home('share'), R.home('include'), R.home('doc'), Sys.getenv("PATH"), getLDLibraryPath(), sep = '\n')
cat("<<<RPLUGIN<<<")
如果 你的R版本不是3 以上
可以尝试:
# Rkernel is an execution kernel for R interpreter
# Copyright (C) 2019 JetBrains s.r.o.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https:#www.gnu.org/licenses/>.
getLDLibraryPath <- function() {
sysinf <- Sys.info()
if (sysinf['sysname'] == "Darwin") Sys.getenv("DYLD_FALLBACK_LIBRARY_PATH")
else if (tolower(sysinf['sysname']) == "linux") {
if(Sys.getenv("LDLIBRARY_PATH") == "") {
sessinf <- sessionInfo()
interpreter_lib_dir <- dirname(sessinf$BLAS)
if (R.version$major <= 3)
paste(dirname(dirname(interpreter_lib_dir)), interpreter_lib_dir, sep=':')
else if (R.version$major > 3)
paste(interpreter_lib_dir, paste0(interpreter_lib_dir, "/R/lib"), sep = ":")
else
""
} else {
Sys.getenv("LDLIBRARY_PATH")
}
}
else ""
}
cat(">>>RPLUGIN>>>")
cat(R.home(), R.home('share'), R.home('include'), R.home('doc'), Sys.getenv("PATH"), getLDLibraryPath(), sep = '\n')
cat("<<<RPLUGIN<<<")
然后 就可以快乐编程了!
自我感悟
这个问题还是很重要的 虽然是基础环境配置 但是也必须要牢牢掌握才是!