You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装tensorflow-gpu遇元数据生成失败错误,如何解决?

问题:安装tensorflow-gpu时出现依赖语法错误

报错信息

A:\Py-Charm\pythonProject> pip install tensorflow-gpu
Collecting tensorflow-gpu
  Using cached tensorflow-gpu-2.12.0.tar.gz (2.6 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [43 lines of output]
      Traceback (most recent call last):
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\requirements.py", line 35, in __init__
          parsed = _parse_requirement(requirement_string)
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 64, in parse_requirement
          return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 82, in _parse_requirement
          url, specifier, marker = _parse_requirement_details(tokenizer)
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 126, in _parse_requirement_details
          marker = _parse_requirement_marker(
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\_parser.py", line 147, in _parse_requirement_marker
          tokenizer.raise_syntax_error(
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\_tokenizer.py", line 165, in raise_syntax_error
          raise ParserSyntaxError(
      setuptools.extern.packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after name and no valid version specifier)
          python_version>"3.7"
                        ^

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\ashwi\AppData\Local\Temp\pip-install-07c73rw5\tensorflow-gpu_1193296dd3aa48408f6cc23cdc8e1ce9\setup.py", line 40, in <module>
          setuptools.setup()
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\__init__.py", line 102, in setup
          _install_setup_requires(attrs)
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\__init__.py", line 73, in _install_setup_requires
          dist.parse_config_files(ignore_option_errors=True)
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\_virtualenv.py", line 23, in parse_config_files
          result = old_parse_config_files(self, *args, **kwargs)
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\dist.py", line 667, in parse_config_files
          self._finalize_requires()
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\dist.py", line 396, in _finalize_requires
          self._normalize_requires()
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\dist.py", line 410, in _normalize_requires
          meta._normalized_install_requires = {
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\dist.py", line 410, in <dictcomp>
          meta._normalized_install_requires = {
        File "A:\Py-Charm\pythonProject\.venv\lib\site-packages\setuptools\_vendor\packaging\requirements.py", line 37, in __init__
          raise InvalidRequirement(str(e)) from e
      setuptools.extern.packaging.requirements.InvalidRequirement: Expected end or semicolon (after name and no valid version specifier)
          python_version>"3.7"
                        ^
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

环境信息

Python Version: 3.9.13
CUDA Installed: Yes
cuDNN Installed: Yes
GPU: RTX 4070
IDE: PyCharm

已尝试的步骤

  • 确认CUDA和cuDNN安装无误
  • 检查TensorFlow版本与GPU架构的兼容性
  • 验证Python版本与TensorFlow的兼容性

解决方案

核心原因

TensorFlow从2.10版本开始,已经不再单独提供tensorflow-gpu包,官方将CPU和GPU版本合并为同一个tensorflow包。你安装的tensorflow-gpu==2.12.0是过时的遗留包,其依赖声明语法不符合新版setuptools的解析规则,导致元数据生成失败。

具体操作步骤

  1. 清理旧包(如果有残留)
    执行命令卸载可能存在的tensorflow-gpu:

    pip uninstall tensorflow-gpu -y
    
  2. 安装官方统一版TensorFlow
    根据你的Python3.9和RTX4070(支持CUDA 11.8或12.x),推荐安装TensorFlow 2.15.0(长期支持版)或2.16.0:

    pip install tensorflow==2.15.0
    
  3. 验证GPU是否可用
    在Python环境中运行以下代码,确认TensorFlow是否成功调用GPU:

    import tensorflow as tf
    print(tf.config.list_physical_devices('GPU'))
    

    如果输出包含你的RTX4070设备信息,说明安装成功。


内容的提问来源于stack exchange,提问作者Ashwin S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:58:13