3

我正在尝试在 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'
>>>
4

1 回答 1

6

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

于 2013-03-18T16:06:54.587 回答