1

我正在使用 Python 的基本入门示例,但遇到了问题。似乎找不到我使用“pip install crazy”安装的 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 quiet”安装了 Keen SDK。有什么办法可以解决这个问题?

4

1 回答 1

4

将您的脚本从重命名keen.pykeentest.py. 您自己的程序的名称会隐藏keen包,这就是keen.client无法导入的原因。

于 2016-03-07T19:50:38.157 回答