Python agent newrelic installation

蓝咒 提交于 2020-02-07 07:45:11

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/28549979/python-agent-newrelic-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!