在另一台机器上导入 Tensorflow 错误

问题描述 投票:0回答:1

我的家用电脑上一切正常。但是当我将带有环境的项目转移到服务器时,Tensorflow开始出现错误:

C:\Users\Administrator>cd C:\Users\Administrator\Desktop\MyProject\venv\Scripts

C:\Users\Administrator\Desktop\MyProject\venv\Scripts>activate.bat

(venv) C:\Users\Administrator\Desktop\MyProject\venv\Scripts>python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\__init__.py", line 42, in <module>
    from tensorflow.python import tf2 as _tf2
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\python\tf2.py", line 21, in <module>
    from tensorflow.python.platform import _pywrap_tf2
ImportError: DLL load failed while importing _pywrap_tf2: The specified module could not be found.

activate.bat:https://pastebin.com/esKmGvw2

另一个 Python 版本的另一个错误:

C:\Users\Administrator\Desktop\MyProject\venv\Scripts>activate.bat

(venv) C:\Users\Administrator\Desktop\MyProject\venv\Scripts>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
>>> import tensorflow
2024-04-22 23:14:49.562778: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\__init__.py", line 45, in <module>
    from tensorflow._api.v2 import __internal__
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\_api\v2\__internal__\__init__.py", line 8, in <module>
    from tensorflow._api.v2.__internal__ import autograph
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\_api\v2\__internal__\autograph\__init__.py", line 8, in <module>
    from tensorflow.python.autograph.core.ag_ctx import control_status_ctx # line: 34
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\python\autograph\core\ag_ctx.py", line 21, in <module>
    from tensorflow.python.autograph.utils import ag_logging
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\python\autograph\utils\__init__.py", line 17, in <module>
    from tensorflow.python.autograph.utils.context_managers import control_dependency_on_returns
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\python\autograph\utils\context_managers.py", line 19, in <module>
    from tensorflow.python.framework import ops
  File "C:\Users\Administrator\Desktop\MyProject\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 5906, in <module>
    ) -> Optional[Callable[[Any], message.Message]]:
  File "C:\Program Files\Python39\lib\typing.py", line 243, in inner
    return func(*args, **kwds)
  File "C:\Program Files\Python39\lib\typing.py", line 316, in __getitem__
    return self._getitem(self, parameters)
  File "C:\Program Files\Python39\lib\typing.py", line 433, in Optional
    return Union[arg, type(None)]
  File "C:\Program Files\Python39\lib\typing.py", line 243, in inner
    return func(*args, **kwds)
  File "C:\Program Files\Python39\lib\typing.py", line 316, in __getitem__
    return self._getitem(self, parameters)
  File "C:\Program Files\Python39\lib\typing.py", line 421, in Union
    parameters = _remove_dups_flatten(parameters)
  File "C:\Program Files\Python39\lib\typing.py", line 215, in _remove_dups_flatten
    all_params = set(params)
TypeError: unhashable type: 'list'
  • 家用电脑:Windows 11 x64,Python 3.9.13
  • 服务器:安装了 Windows Server 2022 21H2、Microsoft Visual C++ 2015-2022 Redistributable x64。
  • TF版本:2.16.1(最新keras的最大支持版本)
python tensorflow
1个回答
0
投票

在服务器上安装类似版本的 Python 的平庸方式对我有帮助(3.9.13 而不是 3.9.0)

© www.soinside.com 2019 - 2024. All rights reserved.