Pythonanfänger: (PYTHON) lxml kann keinen URI öffnen

Hi,

Ich hab Probleme mit lxml.

a) Python 3.1:

  
from lxml import etree  
  
tree = etree.parse('www.google.de')  

Ergebnis:

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

================================ RESTART ================================

Traceback (most recent call last):
  File "C:\Dokumente und Einstellungen\MyName\Eigene Dateien\hello.py", line 3, in <module>
    tree = etree.parse('www.google.de')
  File "lxml.etree.pyx", line 2692, in lxml.etree.parse (src/lxml/lxml.etree.c:49594)
  File "parser.pxi", line 1500, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:71364)
  File "parser.pxi", line 1529, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:71647)
  File "parser.pxi", line 1429, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:70742)
  File "parser.pxi", line 975, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:67740)
  File "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:63824)
  File "parser.pxi", line 625, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:64745)
  File "parser.pxi", line 563, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:64060)
IOError: Error reading file 'b'www.google.de'': b'failed to load external entity "www.google.de"'

Und ja: www.google.de war zu diesem Zeitpunkt problemlos über den normalen Browser erreichbar.
OS: WinXP (32 Bit)
Für Python 3.1 habe ich "python-3.1.1.msi" von der offiziellen Python-Homepage heruntergeladen und als Admin installiert. lxml habe ich mit der Datei "lxml-2.2.4.win32-py3.1.exe" von der Seite http://pypi.python.org/pypi/lxml/2.2.4 heruntergeladen und als Admin installiert. Das in der Installationsanleitung erwähnte "easy_install" kam nicht zum Einsatz, da es für Python 3.1 keine offizielle Version davon gibt.

b) Python 2.6

Ebenfalls WinXP (32 Bit). Python-2.6-Installation damals von einer Buch-CD. Hier wollte ich nun mal kucken, ob es am fehlenden "easy_install" lag. Als Admin bei geöffneter Internetverbindung easy_install gestartet:

C:\Python26\Scripts>easy_install-2.6 lxml
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.2.4
Downloading http://codespeak.net/lxml/lxml-2.2.4.tgz
Processing lxml-2.2.4.tgz
Running lxml-2.2.4\setup.py -q bdist_egg --dist-dir c:\dokume~1\admin\lokale~1\t
emp\easy_install-b3mrsh\lxml-2.2.4\egg-dist-tmp-wfh4is
Building lxml version 2.2.4.
NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' need
s to be available.
ERROR: Der Befehl "xslt-config" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
warning: no files found matching 'lxml.etree.c' under directory 'src\lxml'
warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml'
warning: no files found matching 'lxml.etree.h' under directory 'src\lxml'
warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml'
warning: no files found matching 'etree_defs.h' under directory 'src\lxml'
warning: no files found matching 'pubkey.asc' under directory 'doc'
warning: no files found matching 'tagpython*.png' under directory 'doc'
error: Setup script exited with error: Unable to find vcvarsall.bat

C:\Python26\Scripts>

Hm? Wieso muss ich "development packages" von libxml2 und libxslt installiert haben, wenn ich doch "easy_install" nutze? Und warum stand davon nichts in der lxml-Installationsanleitung? Und überhaupt: Sollte mir solcher Konfigurationskram durch "easy_install" nicht gerade abgenommen werden? Oder läuft bei mir irgendwas Grundsätzliches schief?

Wäre schön, wenn mir jemand einen Tipp geben könnte, wie ich lxml zum Laufen kriege, egal mit welcher Python-Version!

Viele Grüße
Pythonanfänger

  1. Hi!

    tree = etree.parse('www.google.de')
    IOError: Error reading file 'b'www.google.de'': b'failed to load external entity "www.google.de"'

    Aus der Dokumentation:

    The parse() function supports any of the following sources:

    * an open file object
        * a file-like object that has a .read(byte_count) method returning a byte string on each call
        * a filename string
        * an HTTP or FTP URL string

    Sieht wohl so aus, als ob 'www.google.de' als Dateiname angesehen wird. Eine vollständige URL sieht auch etwas anders aus.

    Lo!

    1. Hallo, danke für die Antwort.

      Sieht wohl so aus, als ob 'www.google.de' als Dateiname angesehen wird. Eine vollständige URL sieht auch etwas anders aus.

      Ich nehme an, du meinst http://www.google.de statt www.google.de?

      Leider das gleiche Ergebnis. (Ich hatte ein bisschen damit herumexperimentiert und dann beim Abschicken meiner ersten Nachricht ins Forum vergessen, das wieder wie ursprünglich hinzuschreiben, sorry.)

        
      from lxml import etree  
        
      tree = etree.parse('http://www.google.de')  
      
      

      Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
      Type "copyright", "credits" or "license()" for more information.

      ================================ RESTART ================================

      Traceback (most recent call last):
        File "C:\Dokumente und Einstellungen\MyName\Eigene Dateien\hello.py", line 3, in <module>
          tree = etree.parse('http://www.google.de')
        File "lxml.etree.pyx", line 2692, in lxml.etree.parse (src/lxml/lxml.etree.c:49594)
        File "parser.pxi", line 1500, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:71364)
        File "parser.pxi", line 1529, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:71647)
        File "parser.pxi", line 1429, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:70742)
        File "parser.pxi", line 975, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:67740)
        File "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:63824)
        File "parser.pxi", line 625, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:64745)
        File "parser.pxi", line 563, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:64060)
      IOError: Error reading file 'b'http://www.google.de'': b'failed to load external entity "http://www.google.de"'

      Eventuell noch eine Idee?

      Danke!
      Pythonanfänger