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

Windows11环境Python2.7.9安装python-ldap失败的解决求助

问题

在Windows 11系统的Python 2.7.9环境中安装python-ldap包失败,该包依赖已停止支持的Visual Studio C++ 9.0。由于要进行Odoo 8开发,无法升级Python版本。已尝试下载vcpython2.7但未解决问题,终端报错如下:

ERROR: Command errored out with exit status 1:
     command: 'c:\python27\python2.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'c:\\users\\baash\\appdata\\local\\temp\\pip-req-build-tjzudv\\setup.py'"'"'; __file__='"'"'c:\\users\\baash\\appdata\\local\\temp\\pip-req-build-tjzudv\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'c:\users\baash\appdata\local\temp\pip-record-kndz1b\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python27\Include\python-ldap'
         cwd: c:\users\baash\appdata\local\temp\pip-req-build-tjzudv\
    Complete output (71 lines):
    defines: HAVE_SASL HAVE_TLS HAVE_LIBLDAP_R
    extra_compile_args:
    extra_objects:
    include_dirs: /usr/include /usr/include/sasl /usr/local/include /usr/local/include/sasl
    library_dirs: /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64
    libs: ldap_r
    running install
    running build
    running build_py
    file Lib\ldap.py (for module ldap) not found
    file Lib\ldap\controls.py (for module ldap.controls) not found
    file Lib\ldap\extop.py (for module ldap.extop) not found
    file Lib\ldap\schema.py (for module ldap.schema) not found
    creating build\lib.win-amd64-2.7
    copying Lib\ldapurl.py -> build\lib.win-amd64-2.7
    copying Lib\ldif.py -> build\lib.win-amd64-2.7
    copying Lib\dsml.py -> build\lib.win-amd64-2.7
    creating build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\__init__.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\async.py -> build\lib.win-amd64-2.7\ldap
    creating build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\__init__.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\deref.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\libldap.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\openldap.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\ppolicy.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\psearch.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\pwdpolicy.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\readentry.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\sessiontrack.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\simple.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\controls\sss.py -> build\lib.win-amd64-2.7\ldap\controls
    copying Lib\ldap\cidict.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\dn.py -> build\lib.win-amd64-2.7\ldap
    creating build\lib.win-amd64-2.7\ldap\extop
    copying Lib\ldap\extop\__init__.py -> build\lib.win-amd64-2.7\ldap\extop
    copying Lib\ldap\extop\dds.py -> build\lib.win-amd64-2.7\ldap\extop
    copying Lib\ldap\filter.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\functions.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\ldapobject.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\logger.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\modlist.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\resiter.py -> build\lib.win-amd64-2.7\ldap
    copying Lib\ldap\sasl.py -> build\lib.win-amd64-2.7\ldap
    creating build\lib.win-amd64-2.7\ldap\schema
    copying Lib\ldap\schema\__init__.py -> build\lib.win-amd64-2.7\ldap\schema
    copying Lib\ldap\schema\models.py -> build\lib.win-amd64-2.7\ldap\schema
    copying Lib\ldap\schema\subentry.py -> build\lib.win-amd64-2.7\ldap\schema
    copying Lib\ldap\schema\tokenizer.py -> build\lib.win-amd64-2.7\ldap\schema
    copying Lib\ldap\syncrepl.py -> build\lib.win-amd64-2.7\ldap
    file Lib\ldap.py (for module ldap) not found
    file Lib\ldap\controls.py (for module ldap.controls) not found
    file Lib\ldap\extop.py (for module ldap.extop) not found
    file Lib\ldap\schema.py (for module ldap.schema) not found
    running egg_info
    writing requirements to Lib\python_ldap.egg-info\requires.txt
    writing Lib\python_ldap.egg-info\PKG-INFO
    writing top-level names to Lib\python_ldap.egg-info\top_level.txt
    writing dependency_links to Lib\python_ldap.egg-info\dependency_links.txt
    file Lib\ldap.py (for module ldap) not found
    file Lib\ldap\controls.py (for module ldap.controls) not found
    file Lib\ldap\extop.py (for module ldap.extop) not found
    file Lib\ldap\schema.py (for module ldap.schema) not found
    reading manifest file 'Lib\python_ldap.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'Makefile'
    warning: no files found matching 'Modules\LICENSE'
    writing manifest file 'Lib\python_ldap.egg-info\SOURCES.txt'
    running build_ext
    building '_ldap' extension
    error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python27\python2.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'c:\\users\\baash\\appdata\\local\\temp\\pip-req-build-tjzudv\\setup.py'"'"'; __file__='"'"'c:\\users\\baash\\appdata\\local\\temp\\pip-req-build-tjzudv\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'c:\users\baash\appdata\local\temp\pip-record-kndz1b\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python27\Include\python-ldap' Check the logs for full command output.

解决方案

1. 使用预编译二进制包跳过编译

找适配Python 2.7 Windows平台的python-ldap预编译.whl文件(注意匹配系统位数:64位选win_amd64版本,32位选win32),直接用pip安装:

pip install path/to/python_ldap-<版本号>-cp27-none-win_amd64.whl

2. 修复Visual Studio C++ 9.0环境配置

  • 确认安装的vcpython2.7与系统位数匹配,64位系统必须安装64位版本
  • 打开Visual Studio 2008命令提示符(安装vcpython2.7后会添加到开始菜单),在该环境下执行:
    pip install python-ldap
    
  • 若仍失败,需提前安装Windows版OpenLDAP开发库,通过pip参数指定其路径:
    pip install python-ldap --global-option=build_ext --global-option="-IC:\path\to\openldap\include" --global-option="-LC:\path\to\openldap\lib"
    

3. 切换到WSL环境运行Odoo 8

在Windows 11上启用WSL并安装Ubuntu等Linux发行版:

  • 在WSL中安装依赖:
    sudo apt-get install python2.7 python2.7-dev libldap2-dev libsasl2-dev
    
  • 执行pip install python-ldap完成安装,Linux环境下编译依赖更易满足
  • 后续在WSL中运行Odoo 8开发环境即可

内容的提问来源于stack exchange,提问作者Bagas Muhammad Shaka

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 07:37:03