无法从“ utils”错误导入“ Logger”

时间:2020-05-12 01:39:21

标签: python python-import importerror

无法从utils导入Logger模块,这是我的代码:

import requests
from lxml import html
from utils import Logger

错误是:

Traceback (most recent call last):
  File "C:/Users/Salvatore/Desktop/Python/Preme", line 4, in <module>
    from utils import Logger
ImportError: cannot import name 'Logger' from 'utils' (C:\Users\Salvatore\AppData\Local\Programs\Python\Python38-32\lib\site-packages\utils\__init__.py)

These are a list of my imports, and showing that Logger would not import.

1 个答案:

答案 0 :(得分:0)

实用程序没有名为logger的模块。改用python_utils

运行pip uninstall utils

然后pip install python_utils

最后

# Example 1

from python_utils.logger import Logged

class MyClass(Logged):
    def __init__(self):
        Logged.__init__(self)


my_class = MyClass()
my_class.error('error')

有关python_utils软件包python_utils

的更多信息,

根据您的需要,使用Python内置的日志记录功能还可能更容易:

# Example 2

import logging

logging.error('error')

这里是指向有关日志记录的更多信息的链接,python builtin logging