如何修复Graphite中的daemonize导入错误?

2 投票
2 回答
1706 浏览
提问于 2025-04-18 10:52

我正在配置一个图形监控系统。在按照这个教程 https://gist.github.com/surjikal/2777886 操作时,遇到了一个导入错误:

python /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
  File "/opt/graphite/lib/carbon/util.py", line 21, in <module>
    from twisted.scripts._twistd_unix import daemonize
ImportError: cannot import name daemonize

我在网上搜索了一下,找到了几种可能的解决办法:

1) 从 /opt/graphite/lib/carbon/util.py 文件中删除 daemonize 的导入 (https://answers.launchpad.net/graphite/+question/239063):

from time import sleep, time
from twisted.python.util import initgroups
from twisted.scripts.twistd import runApp
# from twisted.scripts._twistd_unix import daemonize
# daemonize = daemonize # Backwards compatibility

2) 使用 Twisted 13.1.0 版本,而不是更高的版本。

3) 通过 pip 安装 daemonize 并直接导入它 (https://www.digitalocean.com/community/tutorials/installing-and-configuring-graphite-and-statsd-on-an-ubuntu-12-04-vps):

# from twisted.scripts._twistd_unix import daemonize
import daemonize

在 Twisted 环境中,解决这个导入问题最稳定、最可靠的方法是什么?

相关问题:

2 个回答

1

顺便说一下,选项(2)和(3)在我分别尝试时都有效。

对于(2),我运行了:

pip install --user 'Twisted==13.1.0'

(2)看起来比(1)和(3)更可靠,所以如果可以的话,我建议选择这个。

之前我在网上看到的建议是把Twisted降级到小于12.0,但那样做只有和(3)一起使用才有效。

3

我觉得选项(2)是最好的选择,特别是如果你能找到Graphite团队关于Twisted 13.1是支持版本的文档的话(他们应该有记录他们依赖的支持版本)。

如果选择选项(1),你就会让你的安装版本和原始版本不一致。这最终会给管理员带来麻烦。

我很确定选项(3)不会有帮助。daemonize模块只是名字相同,并且做的事情大致相同,但它并不是一个可以直接替代的模块。

撰写回答