从R调用Python代码
我试图从R调用我的python代码。这是我尝试过的一个简单代码从R调用Python代码,r,python-3.x,rpython,R,Python 3.x,Rpython,我试图从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
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'
python.exec(code,get.exception)中的错误:
回溯(最近一次呼叫最后一次):
文件“/home/.local/lib/python2.7/site packages/tensorflow/python/pywrap_tensorflow.py”,第58行,在
从tensorflow.python.pywrap\u tensorflow\u内部导入*
文件“/home/.local/lib/python2.7/site packages/tensorflow/python/pywrap\u tensorflow\u internal.py”,第28行,在
_pywrap\u tensorflow\u internal=swig\u import\u helper()
swig\u import\u helper中的文件“/home/.local/lib/python2.7/site packages/tensorflow/python/pywrap\u tensorflow\u internal.py”,第24行
_mod=imp.load_模块(“pywrap_tensorflow_internal”,fp,路径名,描述)
ImportError:libcublas.so.9.0:无法打开共享对象文件:没有此类文件或目录
未能加载本机TensorFlow运行时。
看见https://www.tensorflow.org/install/install_sources#common_installation_problems
因为一些常见的原因和解决方案。包括整个堆栈跟踪
以上是请求帮助时的错误消息。
此外:警告信息:
在读取行(文件)中:
在“/Desktop/add.py”上找到不完整的最后一行
但是我已经在R中安装了tensorflow作为安装\u tensorflow()。
我找不到问题。有人知道怎么解决这个问题吗 第一条警告消息表示您的TensorFlow文件未添加到指定目录 最后一条消息表示
/Desktop/add.py
的最后一行不是以行尾(EOL)字符结尾的(换行符(\n
)或回车符+换行符(\r\n
)。此消息的初衷是警告您文件可能不完整;大多数数据文件的最后一个字符是EOL字符
要解决此问题,请执行以下操作:
/Desktop/add.py
return