繁体   English   中英

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

[英]Installing Python packages into a virtualenv is not supported on Windows | Tensorflow & Keras for Windows 10

I'm trying to set up for the first time R environment with Keras and Tensorflow installed for Windows 10. This error shows in the RStudio but I tried also to do it from the Anaconda prompt in some other way and even if there's no error I我无法正确导入 Tensorflow。 在 RStudio 中:

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

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

 (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.             

任何意见,将不胜感激。

我在尝试在 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中启动一个新的session

7.3 在控制台面板中输入:

Sys.which("make")

7.4 如果一切正常,就会打印出类似这样的内容:

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

7.5可以关闭RStudio

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

  2. 打开“Anaconda 提示”

9.1 我创建了一个名为“r-reticulate”的新环境,它将使用以前版本的 Python,方法是键入:

conda create --name r-reticulate python=3.6

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

激活 r-reticulate

9.3 提示应该变了

9.4 检查现有环境:

康达信息--envs

9.5 “r-reticulate”环境应用“*”表示

9.6我关闭Anaconda提示

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

install.packages(“遥控器”)

遥控器::install_github(“rstudio/keras”,依赖项 = TRUE)

  1. 启动一个新的 session 并输入:

图书馆(keras)

图书馆(网状)

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

install_keras(方法=“康达”,tensorflow=“1.13.1”)

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

13 如果您成功了,您可以使用以下命令测试 keras:

图书馆(keras)

mnist <- dataset_mnist()

13.3 这应该加载mnist数据集

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

库(张量流)

tf$constant("Hellow Tensorflow")

14.3 您应该收到 output:

张量(“常量:0”,形状=(),dtype=字符串)

好吧,我希望这对你有帮助。 web 中没有孤立的解决方案对我有用。

我遇到了同样的问题,尝试了许多解决方案(包括mutiumi在此报告的一个基于我自己的解决方案,即:为安装选择的 Anaconda 包将是 R 向我报告的一个错误,因为缺少包它无法当我按照他们的程序安装时)没有成功。

我的最终工作解决方案是直接从 Anaconda Navigator 安装所有必要的依赖项:

先决条件

  • 设置并检查所有 Nvidia/CUDA/cuDNN 的东西(剧透:这将非常令人沮丧!)

  • 安装非常基础的依赖(R4.0.2、RStudio 最新(我个人使用预览版)、Rtools 40、Anaconda3)

Python TF 和 Keras 环境

  • 打开 Anaconda 导航器
  • 创建一个新的“r-reticulate”环境(如果您已经使用该名称,则删除它,因为以前的安装)
  • right-click on the python package listed on the right box of the window and select to change the version to 3.7.7 (the dependencies required are not currently supported for python 3.8+, hence I have selected the last supported one:-))
  • 显示“未安装”,点击“更新索引...”,然后 select 并安装(按顺序):
    • 枕头
    • 要求
    • pyyaml
    • h5py
    • 张量流-GPU
    • 张量流中心
    • keras-gpu

在 R 上设置和测试

  • install.packages("keras", dependencies = TRUE)
  •  library(keras) library(tensorflow) # This should load the mnist data set # AKA: check Keras is 0K mnist <- dataset_mnist() # You should receive the output: # Tensor("Const:0", shape=(), dtype=string) # # Moreover, you should see in the starting messages # that your GPU is correctly detected, and ready to be used, # for me (somewhere in the middle): # " # Found device 0 with properties: # pciBusID: 0000:01:00.0 name: Quadro RTX 5000 computeCapability: 7.5 # " # # AKA: check TF-gpu is 0K tf$constant("Hellow Tensorflow")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM