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'
有人可以帮忙吗?感谢
答案 0 :(得分:0)
您需要将脚本重命名为code.py
以外的其他内容。 (并且,还要删除code.pyc
。)问题是您的脚本名称与standard Python module called code冲突,因此当代理尝试import code
时,它最终导入您的脚本,而不是标准模块
请参阅&#34;名称阴影陷阱&#34;有关详细信息:http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap