我试图从R调用我的python代码。这是我尝试过的简单代码。
import tensorflow as tf
a1=tf.constant(23)
b1=tf.constant(25)
s1=tf.Session()
with tf.Session() as s1:
out=s1.run(a1+b1)
print (out)
使用rPython(R-library)我试着调用这个函数。
library(rPython)
# Load/run the main Python script
python.load("/Desktop/add.py")
但是发生了错误。
Error in python.exec(code, get.exception) :
Traceback (most recent call last):
File "/home/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
In addition: Warning message:
In readLines(file) :
incomplete final line found on '/Desktop/add.py'
但是我已经在R中安装了tensorflow作为 install_tensorflow()。 我找不到问题。有谁知道如何解决这个问题?
答案 0 :(得分:0)
第一条警告消息表明您的TensorFlow文件未添加到指定目录。
最后一条消息表明/Desktop/add.py
的最后一行不以行尾(EOL)字符(换行符(\n
)或回车+结尾换行(\r\n
))。此消息的初衷是警告您文件可能不完整;大多数数据文件都有一个EOL字符作为文件中的最后一个字符。
修复它:
/Desktop/add.py
return