Python代理newrelic安装

Python代理newrelic安装,python,newrelic,Python,Newrelic,我试图在我的webapp上安装newrelic的python代理,但我就是做不到。我正在使用一个名为code.py的文件启动我的应用程序。 我在乞讨时补充说: import newrelic.agent newrelic.agent.initialize('newrelic.ini') 我还试着: import newrelic.agent newrelic.agent.initialize('/root/web/newrelic.ini') 但我有一些错误,比如 Traceback

我试图在我的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'

有人能帮忙吗??谢谢

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


有关更多详细信息,请参见名称阴影陷阱的描述:

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