python lxml 3.3.5 - 加载代码时出错 - " ValueError:lxml.etree._Element的大小错误,请尝试重新编译"

时间:2014-06-19 15:20:09

标签: python xml django python-2.7 lxml

我通过pip安装了lxml 3.3.5。现在我在运行一些django测试时遇到了问题:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/south/management/commands/test.py", line 8, in handle
    super(Command, self).handle(*args, **kwargs)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/test/runner.py", line 144, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/test/runner.py", line 63, in build_suite
    tests = self.test_loader.loadTestsFromName(label)
  File "/usr/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "/vagrant/myapp/tests/test_myapp.py", line 12, in <module>
    import dm.xmlsec.binding as xmlsec
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/dm/xmlsec/binding/__init__.py", line 2, in <module>
    from _xmlsec import *
  File "etreepublic.pxd", line 33, in init dm.xmlsec.binding._xmlsec (src/_xmlsec.c:9587)
ValueError: lxml.etree._Element has the wrong size, try recompiling

正如追溯显示的那样,它在加载代码时失败了。如果我尝试从python shell进行导入,它第一次失败:

In [1]: import dm.xmlsec.binding as xmlsec
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-74e93bb8b8dd> in <module>()
----> 1 import dm.xmlsec.binding as xmlsec

/home/vagrant/venv/local/lib/python2.7/site-packages/dm/xmlsec/binding/__init__.py in <module>()
      1 # Copyright (C) 2012 by Dr. Dieter Maurer <dieter@handshake.de>; see 'LICENSE.txt' for details
----> 2 from _xmlsec import *
      3 
      4 def dsig(tag):
      5   """`lxml` tag designator for *tag* in DSig namespace."""

/vagrant/etreepublic.pxd in init dm.xmlsec.binding._xmlsec (src/_xmlsec.c:9587)()

ValueError: lxml.etree._Element has the wrong size, try recompiling

In [2]: import dm.xmlsec.binding as xmlsec

有任何帮助吗?

1 个答案:

答案 0 :(得分:1)

尝试运行:

pip install -I --no-cache lxml==3.3.5
pip uninstall -y dm.xmlsec.binding
pip install --no-cache dm.xmlsec.binding

dm.xmlsec.binding之前安装lxmllxml更改时,我遇到了问题。