Python代理newrelic安装 [英] Python agent newrelic installation

查看:157
本文介绍了Python代理newrelic安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的web应用程序上安装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'

有人可以帮忙吗?谢谢

解决方案

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

有关更多详细信息,请参见名称隐藏陷阱"的描述: http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap

im trying to install python agent of newrelic on my webapp but i just cant. im using a file named code.py to start my app. I add at the begging:

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

and i also tryed:

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

but i get some error like

 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'

can someone help?? thanks

解决方案

You need to rename your script to something other than code.py. (And, also delete code.pyc.) The problem is your script name conflicts with a standard Python module called code, so when the agent tries to import code, it winds up importing your script, not the standard module.

See this description of the "name shadowing trap" for more details: http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap

这篇关于Python代理newrelic安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆