CentOS安装python_ldap和PIL

1.安装django_auth_ldap需要依赖python_ldap,  openldap

     CentOS要实现openLDAP必须先安装openldap,  openldap-servers,  openldap-clients三个包。第一个默认已经安装好了。

     默认easy_install或者pip install很容易遇到这个错误


/usr/include/sasl/sasl.h:349: 警告:函数声明不是一个原型
Modules/ldapcontrol.c: In function ‘encode_assertion_control’:
Modules/ldapcontrol.c:352: 警告:隐式声明函数 ‘ldap_create_assertion_control_value’
Modules/constants.c: In function ‘LDAPinit_constants’:
Modules/constants.c:155: 错误:‘LDAP_OPT_DIAGNOSTIC_MESSAGE’ 未声明 (在此函数内第一次使用)
Modules/constants.c:155: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
Modules/constants.c:155: 错误:所在的函数内只报告一次。)
Modules/constants.c:365: 错误:‘LDAP_CONTROL_RELAX’ 未声明 (在此函数内第一次使用)
error: Setup script exited with error: command 'gcc' failed with exit status 1

原因是版本不兼容,centos默认装了个2.3的。以下指令好使

yum install openldap
yum install openldap24-libs
yum install openldap-clients
yum install openldap-devel
yum install openssl-devel
yum install openldap24-libs-devel
export CPATH=/usr/include/openldap24
export LIBRARY_PATH=/usr/lib/openldap24/     (以上为安装openldap)
pip install python-ldap

pip install django_auth_django(依赖python_ldap)

验证OK了没:

验证Python_ldap(Python交互模式,命令行下)

>>>import ldap
>>>conn = ldap.initialize("ldap://ip:port")    ip  port写自己的实际配置
>>>conn.protocol_version = 3
>>>conn.set_option(ldap.OPT_REFERRALS, 0)
>>>conn.simple_bind_s('账号', '密码')

验证django_auth_ldap安装好并且配置好了(前提是 已经对着 django_auth_ldap文档配置了django  settings文件)

python manage.py shell

>>>from django_auth_ldap.backend import LDAPBackend  #import 失败说明没有安装好

>>>ldapobj = LDAPBackend()

>>>ldapobj.authenticate('账号','密码')

<class 'django.contrib.auth.models.User'>如果报错,,没有配置好,认证失败。跟着错误提示改改,django_auth_ldap就配好了


2.安装PIL

1.windows就不说了   报错 error: Unable to find vcvarsall.bat

要么安装  VS使用其编译器,还得改改别的文件,麻烦,几个G懒得下

要么直接安装Pillow,找exe版。http://www.lfd.uci.edu/~gohlke/pythonlibs/

不要安装exe版本的pil,  64位系统不好使。人品好的话,exe版本的pil也行。既然都windows了   就pillow得了


2,Centos

安装完啥错不报,使用时报错  The _imaging C module is not installed

缺少devel

安装PIL  PIllow结束时注意看总结 “Summary“,写的很清楚哪些可用哪些不可用,不要以为没报错出了一大堆打印信息就算安装好了。

yum install freetype-devel libjpeg-devel lib-devel
pip uninstall pil Pillow
pip install pil pillow

pil   pillow不是必须一起装,上述命令中不需要哪个 就不写哪个,上述命令仅仅简写  一次卸载 或 安装2个。


验证Pillow

from PIL import Image

验证pil

import Image

不报错算安装OK






你可能感兴趣的:(python,PIL,dj,pillow)