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

标签 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 并错误地删除了该模块? ,

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

是否可以追踪 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/

相关文章:

python - 在 Python 中将撇号保存在 re.sub 中

python - 如何在 Pandas DataFrame 上添加列标签

python - subprocess.Popen - 再次重定向标准输入

python - 可调用模块

javascript - 更改模块名称大小写时,Webpack 使 bundle 无效

python - 没有名为 pyglet 的模块

python - 处理 python 字典以删除不需要的元素并保留所需的元素

python - 为什么当我使用 pip install beautifulsoup 时只有 egg-info 而没有实际的模块?

shell - pip 没有卸载软件包

pandas - 如果pandas使用xlsxwriter为什么我想直接使用它时必须安装它?