Ich verwende PyDev mit Python 3.5 von Aptana Installation. Alles hat gut funktioniert, bis ich mich entschied, das Logging-Modul zu erforschen, das ich vorher noch nie benutzt habe. Ich begann mit neuen Skript aus dem Tutorial:Fehler bei der Python-Protokollierung von Pydev
import logging
logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
in Pydev ich diesen Fehler habe:
Traceback (most recent call last):
File "C:\Users\Tomasz\workspace\basicLogging.py", line 7, in <module>
logging.warning('Watch out!') # will print a message to the console
AttributeError: module 'logging' has no attribute 'warning'
ich gesucht und gefunden Fragen wie: python : install logging module mit ähnlichem Problem, aber keine Lösung. Offensichtlich ist das Problem nicht mit der Installation. Wenn ich genau das gleiche Skript von CMD ausführe, habe ich korrekte Ausgabe. Im Moment scheint es so, als ob Pydev mir bei den meisten meiner Skripte einen Fehler gibt. Wenn ich wieder zu dem Code komme, der vorher gut geklappt hat, habe ich jetzt folgendes:
Traceback (most recent call last):
File "C:\Users\Tomasz\workspace\piClientFullQt.py", line 15, in <module>
from matplotlib.backends import qt_compat
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\cbook.py", line 33, in <module>
import numpy as np
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\__init__.py", line 180, in <module>
from . import add_newdocs
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\core\__init__.py", line 58, in <module>
from numpy.testing.nosetester import _numpy_tester
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\testing\__init__.py", line 10, in <module>
from unittest import TestCase
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\unittest\__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\lib\unittest\case.py", line 273, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'
Ich bin mir nicht sicher, wie das passiert ist. Wenn ich print(sys.executable)
mache gibt es den gleichen Pfad C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\python3.exe
in beiden Fällen, CMD läuft gut und Pydev gibt Fehler.
Ich habe ein Problem mit einigen Python-Variablen in Pydev (ich denke), aber kann nicht finden, wie man es repariert.
EDIT: ich this Frage suchen und versucht, die Antworten
Lage von Python-Interpreter korrekt ist, und es sieht aus wie ich alle Libs haben, was ich
C:\Users\Tomasz>python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
C:\Users\Tomasz\AppData\Local\Programs\Python\Python35-32\Lib\site-packages
Und Website-Pakete müssen sind bereits im System PYHONPATH
Ich habe versucht, Standardeinstellungen in Window -> Einstellungen -> PyDev -> Iterpreters -> Python Interpreter
EDIT: @Samuel advise Nach versuche ich:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
und in PyDev ich habe:
Traceback (most recent call last):
File "C:\Users\Tomasz\workspace\SCT2python\goodExamps\logging\basicLogging.py", line 3, in <module>
logger = logging.getLogger()
AttributeError: module 'logging' has no attribute 'getLogger'
Es funktioniert gut, wenn ich es in der Kommandozeile als Script ausführen! !
BEARBEITEN SIE: DIE LÖSUNG Dank @Samuel finde ich heraus, dass ich absolut dummen Fehler gemacht habe! Bevor ich anfing, mit der Bibliothek zu spielen, machte ich einen Ordner, um meine Skripte zu behalten, und dumm nannte ich das "Logging". Offensichtlich löste das Umbenennen des Ordners das Problem!
Sieht aus wie etwas überschatt build-n-Logger lib. Haben Sie in Ihrem Projekt andere Module namens 'logging'? Wenn nicht, gehe zur Erklärung von 'Logging' und sag mir, welche Datei geöffnet ist – Samuel
@Samuel du bist ein Star! Ich habe einen so dummen Fehler gemacht! – tomasz74
@Samuel Sie sind ein Live-Sparer. War kurz davor, meine Haare zu ziehen – dter