Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';XPathExpr';对象没有属性';添加“后置条件”';_Python_Windows_Lxml_Pyquery - Fatal编程技术网

Python 属性错误:';XPathExpr';对象没有属性';添加“后置条件”';

Python 属性错误:';XPathExpr';对象没有属性';添加“后置条件”';,python,windows,lxml,pyquery,Python,Windows,Lxml,Pyquery,我正在尝试在Windows上安装,当我尝试这样选择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 inform

我正在尝试在Windows上安装,当我尝试这样选择
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'
>>>
Python 2.7.3(默认值,2012年4月10日23:31:26)[MSC v.1500 32位(英特尔)]在win上
32
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从pyquery将pyquery导入为pq
>>>d=pq(“”)
>>>d(‘p:第一’)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\lib\site packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
“,第237行,呼叫中”__
结果=self.\uuuuu类(*参数,父=self,**kwargs)
文件“C:\Python27\lib\site packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
“,第213行,在_init中__
xpath=self.\u css\u to\u xpath(选择器)
文件“C:\Python27\lib\site packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
“,第223行,在_css_to_xpath中
返回self.\u translator.css\u到\u xpath(选择器,前缀)
css-to-xpath中第188行的文件“build\bdist.win32\egg\cssselect\xpath.py”
文件“build\bdist.win32\egg\cssselect\xpath.py”,第188行,在
文件“build\bdist.win32\egg\cssselect\xpath.py”,第208行,在选择器\u到\u xpat中
H
xpath中的文件“build\bdist.win32\egg\cssselect\xpath.py”,第230行
文件“build\bdist.win32\egg\cssselect\xpath.py”,第272行,在xpath\u中
文件“C:\Python27\lib\site packages\pyquery-1.2.4-py2.7.egg\pyquery\cssselectp
xpath_first_pseudo中的第19行“atch.py”
xpath.add_post_条件('position()=1')
AttributeError:'XPathExpr'对象没有属性'add\u post\u条件'
>>>

我用“easy\u install pyquery”安装了pyquery,这导致了这个错误。
我删除了它,然后用
python setup.py install安装了它,现在它开始工作了。

PyQuery修补了
cssselect
XPathExpr
类以添加
add\u post\u condition
方法。看来这是失败的。检查您的
css选择
版本,或者将其升级到最新版本?
pip uninstall pyquery
,然后执行
pip install git+git://github.com/gawel/pyquery.git
(不需要克隆然后安装,只需一次完成即可)也为我修复了此问题。