无法导入张量流,OSError: [WinError 193] %1 不是有效的 Win32 应用程序



我正在尝试使用anaconda为python(3.7(安装TensorFlow。我已经安装了Cuda 10.2和匹配的cndd,并将其安装在一个虚拟环境中:

pip install tensorflow==2.1.0

该命令运行时没有任何错误,但当我尝试在python中导入它时,我得到了:

    Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 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 "<stdin>", line 1, in <module>
  File "C:UsersabualAnaconda3envsml1libsite-packagestensorflow__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:UsersabualAnaconda3envsml1libsite-packagestensorflow_core__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked
  File "C:UsersabualAnaconda3envsml1libsite-packagestensorflow__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:UsersabualAnaconda3envsml1libsite-packagestensorflow__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:UsersabualAnaconda3envsml1libimportlib__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:UsersabualAnaconda3envsml1libsite-packagestensorflow_corepython__init__.py", line 47, in <module>
    import numpy as np
  File "C:UsersabualAppDataRoamingPythonPython37site-packagesnumpy__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:UsersabualAppDataRoamingPythonPython37site-packagesnumpy_distributor_init.py", line 26, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:UsersabualAnaconda3envsml1libctypes__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>>

有人能帮我解决吗?感谢

关于您的第一个问题

问题可能是在64位机器上安装32位。,请尝试安装64位TensorFlow 2.x版本。请参阅此处的文件

关于您的第二个问题

tf.Session((在1.x版本上,您需要将其迁移到2.1。你可以在这里阅读有关迁移的

请参考下面的样本代码

# Using the `close()` method.
sess = tf.compat.v1.Session()
sess.run(...)
sess.close() 

相关内容

  • 没有找到相关文章

最新更新