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

时间:2019-01-22 13:01:46

标签: python module pip redhat graphite

我想参与所有有关奇怪问题的操作(操作系统是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并错误地删除了该模块? ,

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

是否可以追溯点记录历史或找到删除模块的原因?

仅提供更多信息,这是使用模块的脚本,

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))

1 个答案:

答案 0 :(得分:1)

pip具有--log option,但默认情况下未启用,因此除非启用了该选项(在这种情况下似乎不太可能),否则您将无法跟踪点子历史记录。无论如何,一个简单的“ pip install carbon”应该足以重装该模块,就像什么也没发生一样。

如果您真的需要找出计算机上发生的情况,则可以始终尝试检查shell历史记录文件(bash的〜/ .bash_history),并找出使用“ last”记录的人,但这是取证的问题而不是Python问题。