python – pyad:安装得很好,但说无法找到adbase

这让我非常困惑.我用pip安装了pyad,一切似乎都很好:

C:\WINDOWS\system32>pip install pyad
Collecting pyad
  Using cached pyad-0.5.16.tar.gz
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python35\lib\site-packages (from pyad)
Requirement already satisfied (use --upgrade to upgrade): pywin32 in c:\python35\lib\site-packages (from pyad)
Installing collected packages: pyad
  Running setup.py install for pyad ... done
Successfully installed pyad-0.5.16

但是当我尝试使用它时,我收到一个错误,抱怨没有找到adbase:

C:\WINDOWS\system32>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyad import aduser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python35\lib\site-packages\pyad\__init__.py", line 1, in <module>
    from adbase import set_defaults as pyad_setdefaults
ImportError: No module named 'adbase'
>>> import pyad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python35\lib\site-packages\pyad\__init__.py", line 1, in <module>
    from adbase import set_defaults as pyad_setdefaults
ImportError: No module named 'adbase'

这很奇怪,因为如果我尝试卸载pyad或者如果我检查site-packages目录,那么adbase肯定存在:

C:\WINDOWS\system32>pip uninstall pyad
Uninstalling pyad-0.5.16:
  c:\python35\lib\site-packages\pyad-0.5.16-py3.5.egg-info
  c:\python35\lib\site-packages\pyad\__init__.py
  c:\python35\lib\site-packages\pyad\__pycache__\__init__.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\adcomputer.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\addomain.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\adgroup.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\adquery.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\adsearch.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\__pycache__\pyad.cpython-35.pyc
  c:\python35\lib\site-packages\pyad\adbase.py
  c:\python35\lib\site-packages\pyad\adcomputer.py
  c:\python35\lib\site-packages\pyad\adcontainer.py
  c:\python35\lib\site-packages\pyad\addomain.py
  c:\python35\lib\site-packages\pyad\adgroup.py
  c:\python35\lib\site-packages\pyad\adobject.py
  c:\python35\lib\site-packages\pyad\adquery.py
  c:\python35\lib\site-packages\pyad\adsearch.py
  c:\python35\lib\site-packages\pyad\aduser.py
  c:\python35\lib\site-packages\pyad\pyad.py
  c:\python35\lib\site-packages\pyad\pyadconstants.py
  c:\python35\lib\site-packages\pyad\pyadexceptions.py
  c:\python35\lib\site-packages\pyad\pyadutils.py
Proceed (y/n)?

pyad directory contents

我真的不确定还有什么可以尝试的.我在提升的命令提示符下运行所有​​内容,因此它不是权限问题.我甚至尝试下载pyad并使用setup.py安装它,但我遇到了同样的问题. adbase肯定存在,我无法弄清楚为什么Python没有找到它.

最佳答案 这是pyad部分的一个错误.他们正在导入adbase,就好像它是一个独立的模块或包,这就是为什么它不起作用.解决此问题的正确方法是将导入更改为从pyad.adbase导入的绝对导入…或从.adbase导入的相对导入….

但是,如果你检查Github上的master分支,你会看到他们已经实际修复了它.但这不是全部,如果你检查他们的setup.py,你会看到Github上的版本是0.5.15,而PyPI上的最后一个版本,你已经安装的版本是0.5.16.奇怪的.

我建议你直接从Github安装软件包,这应该解决这个问题.要做到这一点,首先卸载pyad,然后运行

pip install https://github.com/zakird/pyad/archive/master.zip
点赞