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

python + how to know who removed the python module

我想参与所有关于奇怪的问题(OS 是 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_history for bash) 并找到谁是使用 "last" 登录的,但这更像是取证问题而不是 Python 问题。