2013-03-18 101 views
3

我试图在Windows上安装pyquery,当我尝试做这样的选择时,出现以下错误d('p:first')。其他一切似乎都在起作用。任何想法我错过了什么?这个问题只发生在我的Windows机器上,我的MAC工作正常。AttributeError:'XPathExpr'对象没有属性'add_post_condition'

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

PyQuery修补'cssselect'' XPathExpr'类以添加'add_post_condition'方法。看起来在这里失败了。检查你的'cssselect'版本,也许升级到最新版本? – 2013-03-18 12:08:42

回答

6

我已经用“easy_install pyquery”安装了pyquery,这导致了这个错误。 我删除它,然后从https://github.com/gawel/pyquerypython setup.py install安装它,现在它工作。

+5

'pip卸载pyquery'后跟一个'pip install git + git:// github.com/gawel/pyquery.git'(不需要克隆然后安装,可以一次完成)为我解决这个问题以及。 – 2013-03-19 23:21:31