我正在使用Python的基本入门示例,但遇到了问题。似乎找不到使用“ pip install keen”安装的KeenClient

代码如下

from keen.client import KeenClient

# Initialize the Keen Client.
client = KeenClient("56ddb39a96773d7e98d63392", write_key="xxxx")

# Build your event properties as a dictionary.
ticket_purchase = {
  "price" : 50.00,
  "user": {
    "id": "020939382",
    "age": 28
  },
  "artist": {
    "id": "19039",
    "name": "Tycho"
  },
  "venue": {
    "id": "A93DJ",
    "name": "The Fillmore",
    "city": "San Francisco",
    "state": "California"
  }
}
# Add your event to the "ticket_purchases" collection.
client.add_event("ticket_purchases", ticket_purchase)


错误消息如下:

Traceback (most recent call last):
  File "/Users/wim/Dropbox/Programming/Python/keen.py", line 1, in <module>
    import KeenClient
ImportError: No module named KeenClient
[Finished in 0.0s with exit code 1]
[shell_cmd: python -u "/Users/wimw/Dropbox/Programming/Python/keen.py"]
[dir: /Users/wimw/Dropbox/Programming/Python]
[path: /usr/bin:/bin:/usr/sbin:/sbin]


我在MAC上运行,但在Ubuntu上也有此问题。我按照文档中的“ pip install keen”安装了Keen SDK。有什么办法解决这个问题?

最佳答案

将脚本从keen.py重命名为keentest.py之类的名称。您自己的程序的名称遮盖了keen包,这就是为什么无法导入keen.client的原因。

10-07 21:34