如何在 Windows 上安装 xmlsec? (pip install xmlsec 失败)

How to install xmlsec on Windows? (pip install xmlsec fails)

xmlsec docs 建议 pip install xmlsec 应该开箱即用

Starting with 1.3.7, prebuilt wheels are available for Windows, so running pip install xmlsec should suffice.

但是,这引发了错误(见下文)。

我找到了 ,我认为答案表明我需要在安装前添加本机库。但是由于我在 Windows 并且有点初学者,所以我不知道如何安装 libxml2-dev、libxmlsec1-dev 或 libxmlsec1-openssl 等软件包。 pip install libxml2-dev 不起作用,据我所知,我无法在 Windows 上安装 brew。我已经广泛搜索了 SO 和 Google,但无法弄清楚。

我还尝试通过从 bin 文件夹中提取一些文件并将其添加到 PATH 来单独安装 libxml2,如下所述:https://pages.lip6.fr/Jean-Francois.Perrot/XML-Int/Session1/WinLibxml.html,但这也没有用。

Building wheels for collected packages: xmlsec
  Building wheel for xmlsec (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for xmlsec (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [62 lines of output]
      running bdist_wheel
      running build
      running build_py
      package init file 'src\xmlsec\__init__.py' not found (or not a regular file)
      running build_ext
      building 'xmlsec' extension
      constants.c

      ...LOTS OF ERRORS/WARNINGS...

      fatal error C1047: The object or library file 'C:\Users345\AppData\Local\Temp\pip-install-3tfgg6bc\xmlsec_12345\build\tmp\libs\iconv-1.14.win64\lib\iconv_a.lib' was created with an older compiler than other objects; rebuild old objects and libraries
      LINK : fatal error LNK1257: code generation failed
      error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit code 1257
      [end of output]

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

The xmlsec docs suggest that pip install xmlsec should work right out of the box

他们指的是他们为 windows 提供 .whl 个文件这一事实。如果你check the pypi page,你可以确认一下。但是,仅支持 python 3.5-3.9。如果你是 运行 pyhton 3.10,那么会尝试从源代码编译。

看起来 xmlsec 正在从 https://github.com/bgaifullin/libxml2-win-binaries/releases/ 下载 pre-built 库,这些库无法与您的编译器创建的内容链接 on-the-fly (请参阅您的错误消息),因为编译器版本不匹配:

fatal error C1047: The object or library file 'C:\Users345\AppData\Local\Temp\pip-install-3tfgg6bc\xmlsec_12345\build\tmp\libs\iconv-1.14.win64\lib\iconv_a.lib' was created with an older compiler than other objects; rebuild old objects and libraries

我认为解决这个问题的最简单方法是简单地将 python 降级到 3.9,然后使用 pip 安装。 Downloading/compiling 您自己的所需库版本无法解决问题,因为 xmlsec 总是下载它认为需要的版本