Python install Pyldap

"Hello World, Hello Blog"

Posted by Stephen on May 1, 2020

前言

pyldap 出现 “Modules/errors.h:8:10: fatal error: lber.h: 没有那个文件或目录”

环境

系统环境

Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
Linux version :       5.3.0-46-generic ( buildd@lcy01-amd64-013 ) 
Gcc version:         7.5.0  ( Ubuntu 7.5.0-3ubuntu1~18.04 )

Distributor ID:	Deepin
Description:	Deepin 20 Beta
Release:	20 Beta
Codename:	n/a
Linux version :     5.3.0-3-amd64 (debian-kernel@lists.debian.org)
Gcc version:        8.3.0 (Debian 8.3.0-6)
Debian Version     10.4

软件信息

version : 	
     Python 3.7.9

正文

利用pip install python-ldap出现编译错误(见后记一):

Modules/errors.h:8:18: fatal error: lber.h: 没有那个文件或目录

StackOverflow上找到的解决方法:

sudo apt-get install libldap2-dev

这时错误变成了sasl.h缺失(见后记二),继续安装:

sudo apt-get install libsasl2-dev

后记

一、Modules/errors.h:8:10: fatal error: lber.h: 没有那个文件或目录

 Running setup.py install for pyldap ... error
    ERROR: Command errored out with exit status 1:
     command: ~/software/anaconda3/envs/YS/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n3xm_twy/pyldap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n3xm_twy/pyldap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_kukhscl/install-record.txt --single-version-externally-managed --compile --install-headers ~/software/anaconda3/envs/YS/include/python3.7m/pyldap
         cwd: /tmp/pip-install-n3xm_twy/pyldap/
    Complete output (81 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
    creating build/lib.linux-x86_64-3.7
    copying Lib/ldapurl.py -> build/lib.linux-x86_64-3.7
    copying Lib/ldif.py -> build/lib.linux-x86_64-3.7
    copying Lib/dsml.py -> build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/__init__.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/async.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/compat.py -> build/lib.linux-x86_64-3.7/ldap
    creating build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/__init__.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/deref.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/libldap.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/openldap.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/ppolicy.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/psearch.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/pwdpolicy.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/readentry.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/sessiontrack.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/simple.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/controls/sss.py -> build/lib.linux-x86_64-3.7/ldap/controls
    copying Lib/ldap/cidict.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/dn.py -> build/lib.linux-x86_64-3.7/ldap
    creating build/lib.linux-x86_64-3.7/ldap/extop
    copying Lib/ldap/extop/__init__.py -> build/lib.linux-x86_64-3.7/ldap/extop
    copying Lib/ldap/extop/dds.py -> build/lib.linux-x86_64-3.7/ldap/extop
    copying Lib/ldap/filter.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/functions.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/ldapobject.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/logger.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/modlist.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/resiter.py -> build/lib.linux-x86_64-3.7/ldap
    copying Lib/ldap/sasl.py -> build/lib.linux-x86_64-3.7/ldap
    creating build/lib.linux-x86_64-3.7/ldap/schema
    copying Lib/ldap/schema/__init__.py -> build/lib.linux-x86_64-3.7/ldap/schema
    copying Lib/ldap/schema/models.py -> build/lib.linux-x86_64-3.7/ldap/schema
    copying Lib/ldap/schema/subentry.py -> build/lib.linux-x86_64-3.7/ldap/schema
    copying Lib/ldap/schema/tokenizer.py -> build/lib.linux-x86_64-3.7/ldap/schema
    copying Lib/ldap/syncrepl.py -> build/lib.linux-x86_64-3.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 Lib/pyldap.egg-info/PKG-INFO
    writing dependency_links to Lib/pyldap.egg-info/dependency_links.txt
    writing requirements to Lib/pyldap.egg-info/requires.txt
    writing top-level names to Lib/pyldap.egg-info/top_level.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/pyldap.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/pyldap.egg-info/SOURCES.txt'
    running build_ext
    building '_ldap' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/Modules
    gcc -pthread -B ~/software/anaconda3/envs/YS/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.28 -IModules -I/usr/include -I/usr/include/sasl -I/usr/local/include -I/usr/local/include/sasl -I~/software/anaconda3/envs/YS/include/python3.7m -c Modules/LDAPObject.c -o build/temp.linux-x86_64-3.7/Modules/LDAPObject.o
    In file included from Modules/LDAPObject.c:9:
    Modules/errors.h:8:10: fatal error: lber.h: 没有那个文件或目录
     #include "lber.h"
              ^~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: ~/software/anaconda3/envs/YS/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n3xm_twy/pyldap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n3xm_twy/pyldap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_kukhscl/install-record.txt --single-version-externally-mana

二、Modules/LDAPObject.c:21:10: fatal error: sasl.h: 没有那个文件或目录

ERROR: Command errored out with exit status 1:
   command: ~/software/anaconda3/envs/YS/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wkwf7y_n/pyldap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wkwf7y_n/pyldap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-dqe540dg
       cwd: /tmp/pip-install-wkwf7y_n/pyldap/
  Complete output (80 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 bdist_wheel
  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
  creating build/lib.linux-x86_64-3.7
  copying Lib/ldapurl.py -> build/lib.linux-x86_64-3.7
  copying Lib/ldif.py -> build/lib.linux-x86_64-3.7
  copying Lib/dsml.py -> build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/__init__.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/async.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/compat.py -> build/lib.linux-x86_64-3.7/ldap
  creating build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/__init__.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/deref.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/libldap.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/openldap.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/ppolicy.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/psearch.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/pwdpolicy.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/readentry.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/sessiontrack.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/simple.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/controls/sss.py -> build/lib.linux-x86_64-3.7/ldap/controls
  copying Lib/ldap/cidict.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/dn.py -> build/lib.linux-x86_64-3.7/ldap
  creating build/lib.linux-x86_64-3.7/ldap/extop
  copying Lib/ldap/extop/__init__.py -> build/lib.linux-x86_64-3.7/ldap/extop
  copying Lib/ldap/extop/dds.py -> build/lib.linux-x86_64-3.7/ldap/extop
  copying Lib/ldap/filter.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/functions.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/ldapobject.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/logger.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/modlist.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/resiter.py -> build/lib.linux-x86_64-3.7/ldap
  copying Lib/ldap/sasl.py -> build/lib.linux-x86_64-3.7/ldap
  creating build/lib.linux-x86_64-3.7/ldap/schema
  copying Lib/ldap/schema/__init__.py -> build/lib.linux-x86_64-3.7/ldap/schema
  copying Lib/ldap/schema/models.py -> build/lib.linux-x86_64-3.7/ldap/schema
  copying Lib/ldap/schema/subentry.py -> build/lib.linux-x86_64-3.7/ldap/schema
  copying Lib/ldap/schema/tokenizer.py -> build/lib.linux-x86_64-3.7/ldap/schema
  copying Lib/ldap/syncrepl.py -> build/lib.linux-x86_64-3.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 Lib/pyldap.egg-info/PKG-INFO
  writing dependency_links to Lib/pyldap.egg-info/dependency_links.txt
  writing requirements to Lib/pyldap.egg-info/requires.txt
  writing top-level names to Lib/pyldap.egg-info/top_level.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/pyldap.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/pyldap.egg-info/SOURCES.txt'
  running build_ext
  building '_ldap' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/Modules
  gcc -pthread -B ~/software/anaconda3/envs/YS/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.28 -IModules -I/usr/include -I/usr/include/sasl -I/usr/local/include -I/usr/local/include/sasl -I~/software/anaconda3/envs/YS/include/python3.7m -c Modules/LDAPObject.c -o build/temp.linux-x86_64-3.7/Modules/LDAPObject.o
  Modules/LDAPObject.c:21:10: fatal error: sasl.h: 没有那个文件或目录
   #include <sasl.h>
            ^~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyldap
  Running setup.py clean for pyldap
Failed to build pyldap
ERROR: Error checking for conflicts.
Traceback (most recent call last):
  File "~/software/anaconda3/envs/YS/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3021, in _dep_map
    return self.__dep_map
  File "~/software/anaconda3/envs/YS/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/software/anaconda3/envs/YS/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3012, in _parsed_pkg_info
    return self._pkg_info
  File "~/software/anaconda3/envs/YS/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _pkg_info