Seite 1 von 1

Verwendung von pyexpat

Verfasst: Mittwoch 10. April 2013, 19:57
von DerBorsti
Hallo zusammen

ich versuche folgenden Code zuverwenden:

Code: Alles auswählen

import urllib
from xml.dom import minidom

WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s'
WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0'

def weather_for_zip(zip_code):
    url = WEATHER_URL % zip_code
    dom = minidom.parse(urllib.urlopen(url))
    forecasts = []
    for node in dom.getElementsByTagNameNS(WEATHER_NS, 'forecast'):
        forecasts.append({
            'date': node.getAttribute('date'),
            'low': node.getAttribute('low'),
            'high': node.getAttribute('high'),
            'condition': node.getAttribute('text')
        })
    ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0]
    return {
        'current_condition': ycondition.getAttribute('text'),
        'current_temp': ycondition.getAttribute('temp'),
        'forecasts': forecasts,
        'title': dom.getElementsByTagName('title')[0].firstChild.data
    }
Copyright http://developer.yahoo.com/python/python-xml.html

Unabhänig davon dass Yahoo diesen Url Dienst geändert hat kann ich diese Funktion nicht ausführen lassen.

Der Fehler lautet
Traceback (most recent call last):
File "<string>", line 254, in run_nodebug
File "P:\*\TESTGEBIET\pprint.py", line 26, in <module>
weather_for_zip(21465)
File "P:\*\TESTGEBIET\pprint.py", line 9, in weather_for_zip
dom = minidom.parse(urllib.urlopen(url))
File "C:\Program Files\Python27\Lib\xml\dom\minidom.py", line 1919, in parse
from xml.dom import expatbuilder
File "C:\Program Files\Python27\Lib\xml\dom\expatbuilder.py", line 32, in <module>
from xml.parsers import expat
File "C:\Program Files\Python27\Lib\xml\parsers\expat.py", line 4, in <module>
from pyexpat import *
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
Ich habe im Netz schon einige Foren durchsucht und wurde darauf aufmerksam, dass wohl mein PATH nicht richtig gesetzt wurde - deswegen habe ich folgendes gemacht

Code: Alles auswählen

import sys
sys.path.append("C:/Program Files/Python27/Lib/xml/parsers/")
Dennoch funktioniert es nicht - hat jemand eine Idee?

vielen Dank !

Re: Verwendung von pyexpat

Verfasst: Mittwoch 10. April 2013, 21:26
von Sirius3
Hallo DerBorsti,
statt minidom wird in Python üblicherweise ElementTree benutzt. Das hat ein schöneres Interface. Löst zwar nicht Dein Problem, umgeht es aber elegant.

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 11:00
von DerBorsti
Vielen Dank


aber..... auch der ElementTree verwendet expat...

ElementTree.py ausschnitt:

Code: Alles auswählen

    def __init__(self, html=0, target=None, encoding=None):
        try:
            from xml.parsers import expat
        except ImportError:
            try:
                import pyexpat as expat
            except ImportError:
                raise ImportError(
                    "No module named expat; use SimpleXMLTreeBuilder instead"
                    )

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 12:23
von BlackJack
@DerBorsti: Da scheint mir irgendwas mit der Python-Installation nicht zu stimmen, oder es ist ein Python bei dem der entsprechende Parser nicht mitgeliefert wird, warum auch immer.

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 12:43
von DerBorsti
:lol:

ehhh ja das ist nun peinlich ....

die expat.py sowie dessen __init__.py sind leer :P

Jemand ne idee wo ich die finde für win7?

Habe nur diese Seite gefunden: http://expat.sourceforge.net/
Sieht aber eher nach C++ aus als Python

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 12:58
von lunar
@DerBorsti Bitte, versuche nicht, irgendwie expat in Deine existierende Python-Installation zu bekommen. Damit machst Du ziemlich sicher nur noch mehr kaputt.

Installiere Python vollständig neu.

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 13:23
von DerBorsti
Hm okay ... nun bin ich wirklich ratlos...

Da ich ArcGis 10.1 verwende brauche ich auch Python 2.7 um alle programmierten Sachen mit ArcGis abstimmen zukönnen.
Deshalb habe ich nun hier http://www.python.org/download/releases/2.7/ die Version runtergeladen ... aber auch hier ist


expat.py

Code: Alles auswählen

"""Interface to the Expat non-validating XML parser."""
__version__ = '$Revision: 17640 $'

from pyexpat import *
__init__.py

Code: Alles auswählen

"""Python interfaces to XML parsers.

This package contains one module:

expat -- Python wrapper for James Clark's Expat parser, with namespace
         support.

"""
wieder leer
Randnotiz verwende win7 - ist das ein Problem?

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 13:31
von /me
Die Dateien sind doch gar nicht leer. :?:

Re: Verwendung von pyexpat

Verfasst: Donnerstag 11. April 2013, 14:02
von DerBorsti
/me hat geschrieben:Die Dateien sind doch gar nicht leer. :?:
okay falsch ausgedrückt ... mehr als diese beiden datein sind nicht vorhanden ....
ich bekomme immer den error an dieser stelle:

Code: Alles auswählen

from pyexpat import *

Re: Verwendung von pyexpat

Verfasst: Samstag 13. April 2013, 15:38
von Leonidas
Weil pyexpat offensichtlich ein C oder C++-Modul ist, was bei deiner unvollständigen Python-Installation nicht dabei ist.

Re: Verwendung von pyexpat

Verfasst: Sonntag 14. April 2013, 19:19
von DerBorsti
:| Okayyy

Dann frag ich mal so - die jenigen die ElementTree oder Minidom verwenden - welche Installation habt ihr verwendet? Sonder Module installiert?

ich hab diese Installation verwendet (http://www.python.org/download/releases/2.7/) und es beinhaltete nicht das erhoffte Modul

Re: Verwendung von pyexpat

Verfasst: Sonntag 14. April 2013, 19:30
von BlackJack
@DerBorsti: Ich würde ja mindestens mal die aktuellste 2.7er verwenden: http://www.python.org/download/releases/2.7.4/

Und ich installiere das eigentlich immer dorthin wo der Installer vorschlägt, nach ``C:\python27\``.

Re: Verwendung von pyexpat

Verfasst: Montag 15. April 2013, 07:29
von /me
Stackoverflow hatte auch schon mal was zu dem Thema: "pyexpat ImportError: DLL load failed: The specified procedure could not be found".

Eine Neuinstallation von Python in ein anders Verzeichnis könnte daher durchaus das Mittel der Wahl sein.