gpt4 book ai didi

python + 如何知道谁删除了python模块

转载 作者:行者123 更新时间:2023-12-01 08:25:09 25 4
gpt4 key购买 nike

我想参与所有关于奇怪问题的事件(操作系统是redhat 7.2)

我们可以看到carbon.util模块丢失了

/opt/graphite/bin/carbon-cache.py start
Traceback (most recent call last):
File "/opt/graphite/bin/carbon-cache.py", line 28, in <module>
from carbon.util import run_twistd_plugin
ImportError: No module named carbon.util

这是一个新问题,因为几周前一切都很好

所以一个结论是也许有人使用 pip 并错误地删除了该模块? ,

或删除模块的某些操作,或其他假设,

是否可以追踪 pip 历史记录,或者找到删除模块的原因?

只是为了了解更多信息,这是使用该模块的脚本,

more  /opt/graphite/bin/carbon-cache.py
#!/usr/bin/python2
"""Copyright 2009 Chris Davis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""

import sys
import os.path

# Figure out where we're installed
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = os.path.dirname(BIN_DIR)

# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
# source.
LIB_DIR = os.path.join(ROOT_DIR, "lib")
sys.path.insert(0, LIB_DIR)

from carbon.util import run_twistd_plugin
from carbon.exceptions import CarbonConfigException

try:
run_twistd_plugin(__file__)
except CarbonConfigException, exc:
raise SystemExit(str(exc))

最佳答案

pip 有一个 --log option ,但默认情况下它并未启用,因此除非启用该选项(在本例中似乎不太可能),否则您无法跟踪 pip 历史记录。无论如何,一个简单的“pip install Carbon”应该足以重新安装模块,就像什么都没发生一样。

如果你确实需要找出机器上发生了什么,你可以随时尝试检查 shell 历史文件(bash 的 ~/.bash_history)并找出谁使用“last”登录,但这更多的是取证问题比 Python 问题还要多。

关于python + 如何知道谁删除了python模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54308897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com