Reputation: 145
I have a Python script where I import datadog
module. When I run python datadog.py
, it fails with ImportError: cannot import name statsd
. The script starts with following lines:
import os
import mysql.connector
from time import time
from datadog import statsd
Actual error messages are following:
$ python /mnt/datadog.py
Traceback (most recent call last):
File "/mnt/datadog.py", line 5, in <module>
from datadog import statsd
File "/mnt/datadog.py", line 5, in <module>
from datadog import statsd
ImportError: cannot import name statsd
But when I'm in Python shell (started by python
command), I can successfully run from datadog import statsd
. What's the difference here?
By the way, I have proper Python packages installed in my computer:
$ pip freeze | egrep 'datadog|mysql'
datadog==0.17.0
mysql-connector==2.1.6
$ python --version
Python 2.7.5
Upvotes: 1
Views: 652
Reputation: 2814
The problem is that your script is named datadog.py
. So when it imports the module datadog
, it imports itself.
Upvotes: 4