【问题标题】:Tensorflow won't import using AnacondaTensorflow 不会使用 Anaconda 导入
【发布时间】:2020-07-24 09:33:45
【问题描述】:

我试图让 Gpt-2 在 Win10 intel i7 950 上工作,并在 Anaconda(Python 3.5,Tensorflow 1.12)中设置了一个环境,但我什至没有通过张量流的导入。我已经阅读了几个关于类似问题的问题,但没有一个修复/解决方法对我有用。

import tensorflow as tf

Traceback (most recent call last):
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\anaconda3\envs\gpt-2\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 "D:\anaconda3\envs\gpt-2\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\anaconda3\envs\gpt-2\lib\imp.py", line 343, 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 "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\anaconda3\envs\gpt-2\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\anaconda3\envs\gpt-2\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 "D:\anaconda3\envs\gpt-2\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\anaconda3\envs\gpt-2\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

这是我的 Anaconda 环境:

# packages in environment at D:\anaconda3\envs\gpt-2:
#
# Name                    Version                   Build  Channel
absl-py                   0.9.0                    pypi_0    pypi
astor                     0.8.1                    pypi_0    pypi
certifi                   2018.8.24                py35_1
chardet                   3.0.4                    pypi_0    pypi
fire                      0.3.1                    pypi_0    pypi
gast                      0.3.3                    pypi_0    pypi
grpcio                    1.30.0                   pypi_0    pypi
h5py                      2.10.0                   pypi_0    pypi
idna                      2.8                      pypi_0    pypi
importlib-metadata        1.7.0                    pypi_0    pypi
keras-applications        1.0.8                    pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
markdown                  3.2.2                    pypi_0    pypi
numpy                     1.18.5                   pypi_0    pypi
pip                       20.1.1                   pypi_0    pypi
protobuf                  3.12.2                   pypi_0    pypi
python                    3.5.6                he025d50_0
regex                     2017.04.05               pypi_0    pypi
requests                  2.21.0                   pypi_0    pypi
setuptools                40.2.0                   py35_0
six                       1.10.0           py35h06cf344_1
tensorboard               1.12.2                   pypi_0    pypi
tensorflow                1.12.0                   pypi_0    pypi
termcolor                 1.1.0                    pypi_0    pypi
tqdm                      4.31.1                   pypi_0    pypi
urllib3                   1.24.3                   pypi_0    pypi
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_3
werkzeug                  1.0.1                      py_0
wheel                     0.31.1                   py35_0
wincertstore              0.2              py35hfebbdb8_0
zipp                      1.2.0                    pypi_0    pypi

我尝试过升级/降级软件包,但据我了解,Gpt-2 不适用于更高版本的 Python 和 TensorFlow。

*编辑 我尝试了“conda create --name tf_gpu tensorflow-gpu”,它安装了一个完整的 tensorflow 环境,我还尝试降级到 tensorflow 1.5,两者都可以,但它们都不能与 gpt-2 一起使用

*编辑 2 我查看了生成错误消息的代码,尽管消息显示它不是正在加载的 dll。它是一个 .pyd 文件:“\lib\site-packages\tensorflow\python\_pywrap_tensorflow_internal.pyd”

【问题讨论】:

    标签: python tensorflow anaconda


    【解决方案1】:

    即使您进行了 pip 安装,有时在尝试导入 tensorflow 时也可能会出现此 DLL 错误。转到https://www.tensorflow.org/install/pip,然后单击屏幕截图中给出的适用于 Visual Studio 2015、2017 和 2019 的 Microsoft Visual C++ Redistributable。

    现在下载并安装所需的 64 位或 32 位可执行文件。这解决了我的问题。请试试这个。

    【讨论】:

    • 感谢您的回答!我使用您给我的链接安装了 vc_redist.x64.exe。完成没有错误。重新启动 Anaconda powershell 并尝试 import tensorflow as tf,但它给出了完全相同的错误消息。我是否也必须以某种方式将其添加到环境中?
    • conda create -n envname conda activate envname 现在在该环境中执行以下操作:pip install --upgrade tensorflow 安装了 Microsoft Visual C++ Redistributable(在此之后重新启动系统。)检查导入 tensorflow 并且它工作。
    • 如果我按照你的建议升级到 tensorflow 2.2,我可以让它工作,但这对我没有帮助,因为 gpt-2 需要 1.12-1.13.2。我现在查看了源代码,不会加载的模块是 lib\\site-packages\\tensorflow\\python\_pywrap_tensorflow_internal.pyd
    猜你喜欢
    • 2019-05-02
    • 2020-01-10
    • 2018-11-11
    • 1970-01-01
    • 2019-05-02
    • 2018-06-02
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多