AttributeError:'XPathExpr'对象没有属性'add_post_condition'

时间:2013-03-18 10:13:50

标签: python windows lxml pyquery

我正在尝试在Windows上安装pyquery,当我尝试选择此类d('p:first')时出现以下错误。其他一切似乎都在起作用。知道我错过了什么吗?这个问题只发生在我的Windows机器上,我的MAC工作正常。

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyquery import PyQuery as pq
>>> d = pq("<p></p>")
>>> d('p:first')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 237, in __call__
    result = self.__class__(*args, parent=self, **kwargs)
  File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 213, in __init__
    xpath = self._css_to_xpath(selector)
  File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 223, in _css_to_xpath
    return self._translator.css_to_xpath(selector, prefix)
  File "build\bdist.win32\egg\cssselect\xpath.py", line 188, in css_to_xpath
  File "build\bdist.win32\egg\cssselect\xpath.py", line 188, in <genexpr>
  File "build\bdist.win32\egg\cssselect\xpath.py", line 208, in selector_to_xpat
h
  File "build\bdist.win32\egg\cssselect\xpath.py", line 230, in xpath
  File "build\bdist.win32\egg\cssselect\xpath.py", line 272, in xpath_pseudo
  File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\cssselectp
atch.py", line 19, in xpath_first_pseudo
    xpath.add_post_condition('position() = 1')
AttributeError: 'XPathExpr' object has no attribute 'add_post_condition'
>>>

1 个答案:

答案 0 :(得分:6)

我安装了pyquery&#34; easy_install pyquery&#34;这导致了这个错误。 我将其删除,然后使用python setup.py installhttps://github.com/gawel/pyquery安装,现在它正在运行。