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

Windows环境部署Ozone Django服务:依赖包编译安装失败求助

问题:Windows下安装Ozone Django服务依赖失败

背景

我要运行基于Django和React的Ozone服务,克隆了v8.0.0.0-GA版本的项目,进入ozone-framework-python-server目录并创建虚拟环境后,执行pip install -r requirements.txt时出现安装失败,使用的是Windows系统。

首次安装错误日志

Building wheels for collected packages: lxml, psycopg2-binary
  Building wheel for lxml (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [97 lines of output]

   - - -


      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.35.32215\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      *********************************************************************************
      Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
      *********************************************************************************
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lxml
  Running setup.py clean for lxml
  Building wheel for psycopg2-binary (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1

    - - - 
 
      It appears you are missing some prerequisite to build the package from source.
 
      You may install a binary package by installing 'psycopg2-binary' from PyPI.
      If you want to install psycopg2 from source, please install the packages
      required for the build and try again.
 
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.35.32215\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> psycopg2

已尝试的操作

  • 安装了C++构建工具
  • 切换到旧版本pip
  • 安装wheel库
  • 执行pip install --use-pep517 -r requirements.txt,依然报错,错误信息如下:
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.35.32215\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for psycopg2
Failed to build lxml psycopg2
ERROR: Could not build wheels for lxml, psycopg2, which is required to install pyproject.toml-based projects

我猜测是项目长时间未更新导致版本冲突,但不知道具体解决办法。


解决方案

针对lxml安装失败

Windows下编译lxml需要依赖libxml2、libxslt等系统库,直接编译极易失败,推荐安装预编译二进制包:

  • 激活虚拟环境后执行:
pip install lxml --only-binary :all:

如果requirements.txt里指定了lxml版本,补充版本号即可:

pip install lxml==<你的requirements里的版本号> --only-binary :all:

针对psycopg2安装失败

错误提示已明确推荐使用预编译的psycopg2-binary包,直接安装即可:

pip install psycopg2-binary

同样,若requirements.txt指定了版本,加上版本号:

pip install psycopg2-binary==<你的requirements里的版本号>

完整安装流程

先单独安装这两个包,再执行完整依赖安装:

pip install lxml --only-binary :all:
pip install psycopg2-binary
pip install -r requirements.txt

或者直接修改requirements.txt,将psycopg2替换为psycopg2-binary,然后执行:

pip install -r requirements.txt --only-binary lxml,psycopg2-binary

说明

问题根源在于旧项目的依赖包在Windows环境下从源码编译需要额外的系统依赖,而pip默认会尝试源码编译。使用预编译二进制包可以跳过编译步骤,直接完成安装,避免版本和编译环境的适配问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 19:24:52