Windows 不支持将 Python 包安装到 virtualenv | 适用于 Windows 10 的 Tensorflow 和 Keras

Fel*_*iks 2 python r anaconda keras tensorflow

我正在尝试使用为 Windows 10 安装了 Keras 和 Tensorflow 的第一次 R 环境设置。此错误显示在 RStudio 中,但我也尝试以其他方式从 Anaconda 提示符执行此操作,即使没有错误我'无法正确导入 Tensorflow。在 RStudio 中:

> library(keras)
> install_keras(method = "conda", tensorflow = "gpu")
> Error: Installing Python packages into a virtualenv is not supported on Windows
Run Code Online (Sandbox Code Playgroud)

在“conda install -c conda-forge tensorflow”和“pip install --upgrade tensorflow-gpu”之后的Anaconda提示中:

 (base) PS C:\Users\userx> conda activate renv                        
   (renv) PS C:\Users\userx> python                                     
   Python 3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit
   (AMD64)] :: Anaconda, Inc. on win32                                  
   Type "help", "copyright", "credits" or "license" for more
   information.                                                         
    import tensorflow as tf                                                                                                                                                                                                                  Traceback (most recent call last):                                   
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
   line 58, in <module>                                                 
   from tensorflow.python.pywrap_tensorflow_internal import *           
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
   line 28, in <module>                                                 
   _pywrap_tensorflow_internal = swig_import_helper()                                                                                                                                                                                         File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
   line 24, in swig_import_helper                                       
   _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)                                                         
   File "A:\Programy\tools\anaconda3\envs\renv\lib\imp.py", line 242, in
   load_module                                                          
   return load_dynamic(name, filename, file)                            
   File "A:\Programy\tools\anaconda3\envs\renv\lib\imp.py", line 342, in
   load_dynamic                                                         
   return _load(spec)                                                   
   ImportError: DLL load failed: A dynamic link library (DLL)
   initialization routine failed.                                       
   During handling of the above exception, another exception occurred:  
   Traceback (most recent call last):                                   
   File "<stdin>", line 1, in <module>                                  
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\__init__.py",
   line 24, in <module>                                                 
   from tensorflow.python import pywrap_tensorflow  # pylint:
   disable=unused-import                                                
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\__init__.py",
   line 49, in <module>                                                 
   from tensorflow.python import pywrap_tensorflow                      
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
   line 74, in <module>                                                 
   raise ImportError(msg)                                               
   ImportError: Traceback (most recent call last):                      
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
   line 58, in <module>                                                 
   from tensorflow.python.pywrap_tensorflow_internal import *           
   File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
   line 28, in <module>                                                 
   _pywrap_tensorflow_internal = swig_import_helper()                                                                                                                                                                                         File
   "A:\Programy\tools\anaconda3\envs\renv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
   line 24, in swig_import_helper                                       
   _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)                                                         
   File "A:\Programy\tools\anaconda3\envs\renv\lib\imp.py", line 242, in
   load_module                                                          
   return load_dynamic(name, filename, file)                            
   File "A:\Programy\tools\anaconda3\envs\renv\lib\imp.py", line 342, in
   load_dynamic                                                         
   return _load(spec)                                                   
   ImportError: DLL load failed: A dynamic link library (DLL)
   initialization routine failed.                                       
   Failed to load the native TensorFlow runtime.                        
   See https://www.tensorflow.org/install/errors                        
   for some common reasons and solutions.  Include the entire stack
   trace                                                                
   above this error message when asking for help.             
Run Code Online (Sandbox Code Playgroud)

任何意见,将不胜感激。

小智 6

我在尝试在 R 中安装 keras 和 tensorflow 时也遇到了很多问题,但不知何故,经过 5 天的反复试验,我设法做到了。

我不得不将它们安装在装有 Windows 7 Professional 的笔记本中。该笔记本与其他人共享,因此不允许我安装 Windows 10。

  1. 由于频繁出现故障,我决定卸载所有内容:Rtools、RStudio、Anaconda 和 R。因此,我可以从头开始。

  2. 我搜索了一些需要手动删除的剩余文件夹。大多数保存在“C:/Users/Username/”、“C:/Users/Username/Documents”和“C:/Users/Username/AppData/Local”中。当我尝试使用 miniconda 创建的文件夹“r-reticulate”时。这可能就是我那次失败的原因。

  3. 我重置了我的笔记本

  4. 重新安装了最新版本的 R (4.0.2) 和 RStudio (1.3.959)

  5. 重新安装了最新版本的 rtools (40)

  6. 如果 RStudio 处于打开状态,请关闭并重新打开

  7. 我遵循了 rtools 页面中详述的推荐步骤:

7.1 在 RStudio 中,在控制台面板中输入:

writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con="~/.Renviron")

7.2 在 R 中启动一个新会话

7.3 在控制台面板输入:

Sys.which("make")

7.4 如果一切正常,就会打印这样的东西:

"C:\rtools40\usr\bin\make.exe"

7.5 可以关闭RStudio

  1. 我安装了最新版本的 Anaconda 3(尽管它并不真正推荐给 Windows 7 用户)

  2. 打开“Anaconda Prompt”

9.1 我创建了一个名为“r-reticulate”的新环境,它将通过键入以下内容使用以前版本的 Python:

conda create --name r-reticulate python=3.6

9.2 通过激活它来检查一切是否正常:

激活r-网状

9.3 提示应该已经改变

9.4 检查现有环境:

畅达信息--envs

9.5 “r-网状”环境应以“*”表示

9.6 我关闭了Anaconda Prompt

  1. 我重新打开 RStudio 并输入:

install.packages(“遥控器”)

远程 :: install_github(“rstudio/keras”,依赖项 = TRUE)

  1. 开始一个新会话并输入:

图书馆(keras)

图书馆(网状)

use_condaenv("r-reticulate", required = TRUE)

install_keras(method = "conda", tensorflow = "1.13.1")

  1. 注意我使用了以前版本的 tensorflow。一些用户在使用最新版本时遇到问题

13 如果你成功了,你可以用以下方法测试 keras:

图书馆(keras)

mnist <- dataset_mnist()

13.3 这应该加载 mnist 数据集

14 您可以使用以下命令测试 tensorflow:

图书馆(张量流)

tf$constant("你好 Tensorflow")

14.3 你应该收到输出:

Tensor("Const:0", shape=(), dtype=string)

嗯,我希望这对你有帮助。网络中没有孤立的解决方案对我有用。