Pycharm连接远程服务器的Conda环境的R编程使用 Rwrapper文件 libR.so文件丢失找回

问题展开

突然发现,Pycharm上挂着R去运行,这个IDE其实比我们在远程服务器启动Jupyter Notebook 然后挂到隧道上的方式 要稳定和快速得多
因此自己想尝试配一下 在远程服务器上的conda环境里面的 R 能否在本地的Pycharm Professional上直接使用
踩了一些坑 留给大家记录。

插件下载

在这里插入图片描述
下载第一步 先下载插件 在 Pycharm-》File-》Setting-》Plugin 内搜索 插件即可
下载完成后 ,pycharm Professional 创建R project的选项就可以显示了
在这里插入图片描述

激活远程conda环境 架设管道 配置

  1. 登录服务器,conda activate(一定要切到对应的服务器节点)

  2. 架设管道,保证本地的Localhost可以访问在这里插入图片描述

  3. 架设成功后 测试环境是否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<<<")

然后 就可以快乐编程了!

在这里插入图片描述

自我感悟

这个问题还是很重要的 虽然是基础环境配置 但是也必须要牢牢掌握才是!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值