新手用python(一):Windows 使用 pip 安装 python-ldap

在做AD域控LDAP认证的时候,想使用python用来做LDAP数据的同步,其中需要使用python_ldap组件

通过 https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap 下载了最新版本

新手用python(一):Windows 使用 pip 安装 python-ldap_第1张图片

运行安装

C:\Users\Nico\Downloads>pip install python_ldap-3.2.0-cp38-cp38m-win_amd64.whl

 就出现了以下报错

C:\Users\Nico>pip install python_ldap‑3.2.0‑cp38‑cp38m‑win_amd64.whl
Requirement 'python_ldap‑3.2.0‑cp38‑cp38m‑win_amd64.whl' looks like a filename, but the file does not exist
python_ldap‑3.2.0‑cp38‑cp38m‑win_amd64.whl is not a valid wheel filename.
You are using pip version 18.1, however version 19.2.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

这个提示你本地pip版本太低,需要升级,通过执行

 

python -m pip install --upgrade pip

升级

 

C:\Users\Nico>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 119kB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.2.1

C:\Users\Nico>

重新执行pip安装,又出错了 

ERROR: python_ldap-3.2.0-cp38-cp38m-win_amd64.whl is not a supported wheel on this platform.

通过一番查找,发现 没有注意本机安装python的版本型号支持的pip对应版本时,安装错误版本的whl文件会出现:

PIP报错:is not a supported wheel on this platform

解决办法:

1.查看本机python对应支持的库文件版本

Win32

import pip
print(pip.pep425tags.get_supported())

以上我们通过执行可以得出

C:\Python36\Lib\site-packages>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pip
>>> print(pip.pep425tags.get_supported())
[('cp36', 'cp36m', 'win32'), ('cp36', 'none', 'win32'), ('py3', 'none', 'win32'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'),
('py3', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'),
('py30', 'none', 'any')]

该主机支持的库文件版本为cp36-cp36m-win32 

但是在不同主机安装的时候,这个命令执行后出现错误了

C:\Users\Nico\Downloads>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> print(pip.pep425tags.get_supported())
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'pip' has no attribute 'pep425tags'

我对比了之前的主机,发现,除了python版本不一样,还有之前时32位的系统,这次这个是64位系统。是不是这个原因导致命令失效了呢?

一番查找后,发现针对64位系统的查看库文件支持版本的命令是另外一个

win_amd64

import pip._internal
print(pip._internal.pep425tags.get_supported())

执行后得出 

>>> import pip._internal
>>> print(pip._internal.pep425tags.get_supported())
[('cp37', 'cp37m', 'win_amd64'), ('cp37', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'), ('cp37', 'none', 'any'), ('cp3', 'none', 'any'), ('py37', 'none', 'any'), ('py3', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

该主机库文件支持的版本为 cp-37-cp37m-win_amd64 

找到正确的版本后执行安装python_ldap

C:\Users\Nico\Downloads>pip install python_ldap-3.2.0-cp37-cp37m-win_amd64.whl
Processing c:\users\nico\downloads\python_ldap-3.2.0-cp37-cp37m-win_amd64.whl
Collecting pyasn1>=0.3.7 (from python-ldap==3.2.0)
  Downloading https://files.pythonhosted.org/packages/6a/6e/209351ec34b7d7807342e2bb6ff8a96eef1fd5dcac13bdbadf065c2bb55c/pyasn1-0.4.6-py2.py3-none-any.whl (75kB)
     |████████████████████████████████| 81kB 4.9kB/s
Collecting pyasn1-modules>=0.1.5 (from python-ldap==3.2.0)
  Using cached https://files.pythonhosted.org/packages/be/70/e5ea8afd6d08a4b99ebfc77bd1845248d56cfcf43d11f9dc324b9580a35c/pyasn1_modules-0.2.6-py2.py3-none-any.whl
Installing collected packages: pyasn1, pyasn1-modules, python-ldap
Successfully installed pyasn1-0.4.6 pyasn1-modules-0.2.6 python-ldap-3.2.0

C:\Users\Nico\Downloads>

通过 进入python安装目录的Scripts文件夹,执行pip list 查看是否安装成功

D:\Python\Python37\Scripts>pip list
Package        Version
-------------- -------
pip            19.2.1
pyasn1         0.4.6
pyasn1-modules 0.2.6
python-ldap    3.2.0
setuptools     40.6.2

D:\Python\Python37\Scripts>

windows 安装PIP的whl安装包注意事项

1.安装包版本要对应主机安装的python版本及主机系统32/64的区别

2.执行pip install 命令时,进入安装包所在的目录,当然如果不嫌弃要输入一堆目录地址后再加文件名的话这条可以忽略 

 

 

 

你可能感兴趣的:(python)