无法从 'utils' 错误导入 'Logger'
Can not import 'Logger' from 'utils' error
无法从 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)
Utils 没有名为 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')
这里是 link 以了解有关日志记录的更多信息,python builtin logging
无法从 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)
Utils 没有名为 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')
这里是 link 以了解有关日志记录的更多信息,python builtin logging