[英]Error while trying to library rJava from python using rpy2
嘗試使用rpy2
rJava
時遇到問題。 我已經搜索並閱讀了許多問題,但沒有一個能解決我的問題。
我的rJava
環境中的 rJava 安裝正常。
(base) pri@pri:~$ R
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
> library(data.table)
data.table 1.12.8 using 4 threads (see ?getDTthreads). Latest news: r-datatable.com
> library(rJava)
>
但是,當我嘗試使用rpy2
從 Python 加載它時,出現錯誤:
(base) pri@pri:~$ python3
Python 3.7.7 (default, Mar 26 2020, 15:48:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2.robjects as robjects
>>> robjects.r('''library(data.table); library(rJava)''')
R[write to console]: data.table 1.12.8 using 4 threads (see ?getDTthreads). Latest news: r-datatable.com
R[write to console]: Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/pri/R/x86_64-pc-linux-gnu-library/3.6/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pri/anaconda3/lib/python3.7/site-packages/rpy2/robjects/__init__.py", line 416, in __call__
res = self.eval(p)
File "/home/pri/anaconda3/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 198, in __call__
.__call__(*args, **kwargs))
File "/home/pri/anaconda3/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 125, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
File "/home/pri/anaconda3/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py", line 44, in _
cdata = function(*args, **kwargs)
File "/home/pri/anaconda3/lib/python3.7/site-packages/rpy2/rinterface.py", line 623, in __call__
raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/pri/R/x86_64-pc-linux-gnu-library/3.6/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
我已經檢查過二進制文件是否在正確的位置
(base) pri@pri:~$ ls /usr/lib/jvm/default-java/lib/server/
classes.jsa libjsig.so libjvm.so Xusage.txt
並根據 linux 設置正確配置:
(base) pri@pri:~$ cat /usr/lib/R/etc/ldpaths | grep R_JAVA_LD_LIBRARY_PATH
: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/server}
if test -n "${R_JAVA_LD_LIBRARY_PATH}"; then
R_LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}:${R_JAVA_LD_LIBRARY_PATH}"
出於好奇,我還嘗試將 append 這個到 R 的.libPaths()
,但沒有成功:
JDBC_exe = "/usr/lib/jvm/default-java/lib/server/"
robjects.r('''.libPaths(c('{}', .libPaths()))'''\
.format(JDBC_exe))
關於我在這里缺少什么以及如何解決這個問題的任何指針。
當通過以下命令確保環境變量LD_LIBRARY_PATH
的值與 output 兼容時,與動態鏈接相關的大多數問題都應該解決:
python -m rpy2.situation LD_LIBRARY_PATH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.