没有名为“ rpytools”的模块?

时间:2019-02-20 16:30:51

标签: python r anaconda rstudio reticulate

我正在尝试使用R中的网状库。我使用“ functions.py”示例对其进行了测试:

# functions.py file
def add(x, y): 
    return x + y

在R Studio(版本3.5.2)中,这就是我所拥有的:

library(reticulate)  
source_python('functions.py')

但是,这将返回错误:

Error in py_set_attr_impl(x, name, value) : 
  Evaluation error: ModuleNotFoundError: No module named 'rpytools'.

所以我被困在这里。如果有帮助,我还将分享我的Python是64位版本3.6.5。有人知道该怎么做吗?

谢谢

2 个答案:

答案 0 :(得分:1)

安装 reticulate 包,创建 conda env 并安装 keras、tf 和任何你需要的东西。

找到您当前 R 版本的包的存储位置,并找到 reticulate 文件夹,里面应该有一个 python/rpytools 目录。 (在我的例子中,R 包安装在 'C:\Users\abc\Documents\R\win-library\4.1\reticulate\python')

使用此代码:

    library(reticulate)
    sys <- import("sys", convert = TRUE)
    sys$path 

最后一个条目显示了您应该复制 rpytools 文件夹的目录。在此之后,事情开始对我有用。

答案 1 :(得分:0)

rpytoolsreticulate提供的模块,应放在您的模块路径上。例如,我看到:

> library(reticulate)
> sys <- import("sys", convert = TRUE)
> sys$path
 [1] ""                                                                                                          
 [2] "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/bin"                          
 [3] "/Users/kevin/Library/Python/2.7/lib/python/site-packages/pip-18.1-py2.7.egg"                               
 [4] "/Users/kevin/Library/Python/2.7/lib/python/site-packages/virtualenv-16.0.0-py2.7.egg"                      
 [5] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip"                         
 [6] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7"                            
 [7] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin"                
 [8] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac"                   
 [9] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages"
[10] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk"                     
[11] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old"                    
[12] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload"                
[13] "/Users/kevin/Library/Python/2.7/lib/python/site-packages"                                                  
[14] "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages"              
[15] "/Users/kevin/Library/R/3.5/library/reticulate/python"     

请注意最后一个条目,该条目提供了在导入时可以找到rpytools的路径。你看到类似的东西吗?