Python代理newrelic安装 [英] Python agent newrelic installation
问题描述
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屋!