解决Pycharm配置R语言环境报错RWrapper terminated, exitcode: 127

问题

解决Pycharm配置R语言环境报错RWrapper terminated, exitcode: 127 error while loading shared libraries: libR.so: site:stackoverflow.com

原文:Use Conda library path for rwrapper

解决方案

1. 打开GetEnvVars.R文件

打开 C:\Users\UserName\AppData\Roaming\JetBrains\PyCharm版本号\plugins\r-plugin\R\目录下的GetEnvVars.R文件。

  • 注:上面的UserName和PyCharm版本号按实际情况查找,如果没有找到,看下PyCharm的安装目录有没有...\plugins\r-plugin\R\GetEnvVars.R文件,不同版本路径可能有所区别

2.1 R版本大于3

如果R版本大于等于3,将内容替换成文件GetEnvVars.R的内容替换成:

#  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<<<")

2.2 R版本低于3

如果R版本低于3,将内容替换成文件GetEnvVars.R的内容替换成:

#  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<<<")

3. 删除服务器旧配置

找到服务器上.jetbrains_rplugin_helpers文件并删除,大概率是在/home/username/.jetbrains_rplugin_helpers
然后重启Pycharm就可以了。

其他可能的原因

如果上面的方案没有解决,可以尝试下面的解决方案:

  1. 如果是从源码编译安装的,自编译的时候未使用该--enable-R-shlib选项编译 R。(源地址)
    安装教程:Linux下R安装配置以及工具包安装方式
posted @ 2024-07-06 17:46  kingwzun  阅读(12)  评论(0编辑  收藏  举报