[英]Can not import 'Logger' from 'utils' error
Can't import Logger module from utils, Here is what my code looks like:无法从 utils 导入 Logger 模块,这是我的代码的样子:
import requests
from lxml import html
from utils import Logger
Error is:错误是:
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)
Utils doesn't have a module named logger. Utils 没有名为 logger 的模块。 Use python_utils instead
改为使用 python_utils
Run pip uninstall utils
运行
pip uninstall utils
Then pip install python_utils
然后
pip install python_utils
Finally最后
# Example 1
from python_utils.logger import Logged
class MyClass(Logged):
def __init__(self):
Logged.__init__(self)
my_class = MyClass()
my_class.error('error')
Here is more info on the python_utils package, python_utils这是有关 python_utils package、 python_utils的更多信息
Depending on your need, it might also be easier to simply use Python's built in logging capabilities with:根据您的需要,简单地使用 Python 的内置日志记录功能也可能更容易:
# Example 2
import logging
logging.error('error')
Here is a link to the learn more about logging, python builtin logging这是一个链接,可以了解有关日志记录的更多信息, python 内置日志记录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.