【问题标题】:Python agent newrelic installationPython代理newrelic安装
【发布时间】:2015-02-16 20:42:52
【问题描述】:

我试图在我的 webapp 上安装 newrelic 的 python 代理,但我就是不能。我使用名为 code.py 的文件来启动我的应用程序。 我在乞讨时补充:

import newrelic.agent
newrelic.agent.initialize('newrelic.ini')

我也试过了:

 import newrelic.agent
 newrelic.agent.initialize('/root/web/newrelic.ini')

但我遇到了一些错误,例如

 Traceback (most recent call last):
 File "code.py", line 2, in <module>
import newrelic.agent
  File "/usr/local/lib/python2.7/dist-packages/newrelic-        2.44.0.36/newrelic/agent.py", line 1, in <module>
 from .config import initialize, extra_settings
 File "/usr/local/lib/python2.7/dist-packages/newrelic-2.44.0.36/newrelic/config.py", line 34, in <module>
  import newrelic.console
File "/usr/local/lib/python2.7/dist-packages/newrelic-2.44.0.36/newrelic/console.py", line 5, in <module>
  import code
File "/root/web/code.py", line 3, in <module>
 newrelic.agent.initialize('newrelic.ini')
 AttributeError: 'module' object has no attribute 'agent'

有人可以帮忙吗?谢谢

【问题讨论】:

  • 不要截图文本。将错误复制并粘贴到您的问题中。

标签: python newrelic


【解决方案1】:

您需要将脚本重命名为 code.py 以外的名称。 (并且,还要删除code.pyc。)问题是您的脚本名称与standard Python module called code 冲突,因此当代理尝试import code 时,它最终会导入您的脚本,而不是标准模块。

有关详细信息,请参阅“名称阴影陷阱”的描述:http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多