【问题标题】:Installing Python packages into a virtualenv is not supported on Windows | Tensorflow & Keras for Windows 10Windows 不支持将 Python 包安装到 virtualenv 中 |适用于 Windows 10 的 TensorFlow 和 Keras
【发布时间】:2020-09-21 22:24:02
【问题描述】:

我正在尝试为 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

在“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.             

任何建议将不胜感激。

【问题讨论】:

    标签: python r tensorflow keras anaconda


    【解决方案1】:

    我在尝试在 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 提示”

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

    conda create --name r-reticulate python=3.6

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

    激活 r-reticulate

    9.3 提示应该已经改变了

    9.4 检查现有环境:

    conda 信息 --envs

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

    9.6 我关闭了 Anaconda Prompt

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

    install.packages(“远程”)

    remotes::install_github(“rstudio/keras”, dependencies = TRUE)

    1. 开始新会话并进入:

    库(keras)

    图书馆(网状)

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

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

    1. 注意我使用了之前版本的 tensorflow。部分用户在使用最新版本时遇到问题

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

    库(keras)

    mnist

    13.3 这应该会加载 mnist 数据集

    14 您可以使用以下方法测试 tensorflow:

    库(张量流)

    tf$constant("Hellow Tensorflow")

    14.3 你应该会收到输出:

    张量("Const:0", shape=(), dtype=string)

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

    【讨论】:

    • 这个答案非常有帮助,谢谢。我仍然收到一条错误消息,但设法通过在 Python 中安装旧版本的 numpy 来修复它。我使用了以下代码pip uninstall numpy pip install --upgrade numpy==1.16.1
    【解决方案2】:

    我遇到了同样的问题,尝试了很多解决方案(包括mutiumi 在此报告的one,这是我自己的,即:为安装选择的 Anaconda 包将是 R 报告给我的错误由于缺少软件包,当我按照他们的程序进行安装时,它无法安装)而没有成功。

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

    先决条件

    • set up and check 所有 Nvidia/CUDA/cuDNN 的东西(剧透:这会很令人沮丧!)

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

    Python TF 和 Keras 环境

    • 打开 Anaconda 导航器
    • 创建一个新的“r-reticulate”环境(如果您因为之前的安装已经有一个使用该名称的环境,请将其删除)
    • 右键单击窗口右侧框中列出的python包并选择将版本更改为3.7.7(python 3.8+当前不支持所需的依赖项,因此我选择了最后一个支持的: -))
    • 显示“未安装”,点击“更新索引...”,选择安装(按顺序):
      • 枕头
      • 请求
      • 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")
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多