R网状包在winpython中看不到keras库

时间:2017-05-19 13:13:29

标签: python r rstudio keras reticulate

我正在尝试使用在 RStudio 中的Winpython版本3.4.4.amd64中安装的keras库(通过网状和kerasR库)。我在Windows 7 64位机器上工作。我也尝试过使用Winpython版本3.6.1.amd64

我在R中尝试过:

# diagnostics
library(reticulate) 
# reticulate::use_python("PATH_TO_PYTHON") 
path_to_python <- "C:\\dev\\WinPython3.4\\python-3.4.4.amd64"

use_python(path_to_python) 

py_module_available("keras")
[1] FALSE               # it responds with TRUE for eg. matplotlib

py_config()
# python:         C:\dev\WinPython3.4\python-3.4.4.amd64/python.exe
# libpython:      C:/dev/WinPython3.4/python-3.4.4.amd64/python34.dll
# pythonhome:     C:\dev\WINPYT~1.4\PYTHON~1.AMD
# version:        3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC # v.1600 64 bit (AMD64)]
# Architecture:   64bit
# numpy:          C:\dev\WINPYT~1.4\PYTHON~1.AMD\lib\site-packages\numpy
# numpy_version:  1.11.3

当我使用Spyder IDE并加载keras时,它不会给我带来错误。之前我注意修改.keras json文件以使用theano而不是tensorflow。

当我尝试其他libs时,例如py_module_available(“theano”),我得到TRUE。

我不知道我在这里想念的是什么。我想使用keras与库(kerasR)。我在工作,无法修改注册表和环境路径。这是原因吗?

当我尝试

reticulate::import("keras")

我明白了:

Error in py_module_import(module, convert = convert) : 
  AttributeError: 'NoneType' object has no attribute 'write'

Detailed traceback: 
  File "C:\dev\WINPYT~1.4\PYTHON~1.AMD\lib\site-packages\keras\__init__.py", line 2, in <module>
    from . import backend
  File "C:\dev\WINPYT~1.4\PYTHON~1.AMD\lib\site-packages\keras\backend\__init__.py", line 66, in <module>
    sys.stderr.write('Using TensorFlow backend.\n')

我为3.6.1.amd64尝试了相同的结果。 我没有想法,非常感谢所有的建议。

2 个答案:

答案 0 :(得分:1)

关于Keras / theano plz的安装,请在SO

中查看此主题

How do I install Keras and Theano in Anaconda Python on Windows?

完成后重启你的comp ....然后让我们尝试连接来自R studio的kerasR 下面给出(顺序)............

##########深度学习安装&amp;引发
  #### First activate  environment where keras/theano were installed via anaconda prompt  :  

(C:\Users\ADMIN\Anaconda3) C:\Users\ADMIN>activate mydeeplearningmydeeplearning是我的环境名称,我安装了python keras theano等.....

然后从R studio

尝试安装最新的github软件包版本,而不是从头文件.....

devtools::install_github("statsmaths/kerasR")
devtools::install_github("rstudio/reticulate")# install the latest reticulate package as it solves some errors/bugs

library(kerasR)
library(reticulate)

py_available(initialize = FALSE)  # should give TRUE

use_python("C:/Users/ADMIN/Anaconda3/envs/mydeeplearning/python.exe") # plz change it to your Path
keras_init()  # will give `successfully loaded keras`

# further checks if everything is working
keras_available()   # should give `[1] TRUE`
reticulate::py_config()  # should show u]the correct python path which we tried changing initially  using `use_python("C:/Users/ADMIN/Anaconda3/envs/mydeeplearning/python.exe") `

python:         C:/Users/ADMIN/Anaconda3/envs/mydeeplearning/python.exe
libpython:      C:/Users/ADMIN/Anaconda3/envs/mydeeplearning/python35.dll
pythonhome:     C:\Users\ADMIN\ANACON~1\envs\MYDEEP~1
version:        3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Users\ADMIN\ANACON~1\envs\MYDEEP~1\lib\site-packages\numpy
numpy_version:  1.13.1

python versions found: 
 C:/Users/ADMIN/Anaconda3/envs/mydeeplearning/python.exe
 C:\PROGRA~1\Python35\python.exe
 C:\Users\ADMIN\ANACON~1\python.exe
 C:\PROGRA~1\Python35\\python.exe
 C:\Users\ADMIN\ANACON~1/envs/mydeeplearning/python.exe    

reticulate::py_module_available("keras") #should give `[1] TRUE`   
reticulate::py_available()#should give `[1] TRUE`   
reticulate::import("keras.models")# should give `Module(keras.models)`

应该这样做......几乎整整一天安装并找出错误....但现在感到兴高采烈......

答案 1 :(得分:1)

类似地,我在尝试安装R&#34; keras&#34;时遇到了问题。 WIN7下的Anaconda3 5.0.0库。

https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.3.0-cp36-cp36m-win_amd64.whl一直未能安装在Python 3.6(传输/车轮问题)中,看起来像python 3.6兼容性的问题,我确实检查了64位架构:

>>>import platform
>>>platform.architecture()
  

(&#39; 64bit&#39;,&#39; WindowsPE&#39;)

在conda环境r-tensorflow中将PYTHON从3.6降低到3.5并且在R中使用网状物指向该环境:use_condaenv("r-tensorflow")

https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.3.0-cp35-cp35m-win_amd64.whl版本无法正常安装,必须在Python 3.5中使用tensorflow-1.2.1-cp35-cp35m-win_amd64.whl,并且有效

问题是,install_keras()似乎调用install_tensorflow(method = "conda")实际覆盖并使用pip重新安装tensorflow:

activate r-tensorflow && pip install --upgrade --ignore-installed "https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.3.0-cp35-cp35m-win_amd64.whl"

我的猜测是使用&#34; kerasR&#34;而不是&#34; keras&#34;然后库试图强制执行tensorflow-1.2.1-py35。如果您找到了解决方法,请发布。