ModuleNotFoundError:没有名为“couchbase.cluster”的模块;'“couchbase”不是一个包

2024-05-19 08:12:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试导入couchbase.cluster时遇到此错误

我已经通过pip在我的计算机上安装了homebrew和couchbase,在macOS上运行couchbase sdk python文档

代码只是sdk python文档中显示的代码:

from couchbase.cluster import Cluster, ClusterOptions, QueryOptions
from couchbase_core.cluster import PasswordAuthenticator



cluster = Cluster('couchbase://localhost', ClusterOptions(PasswordAuthenticator('username', 'password')))
cb = cluster.bucket('bucket-name')
cb_coll = cb.default_collection()
cb_coll.upsert('u:king_arthur',
               {'name': 'Arthur', 'email': 'kingarthur@couchbase.com', 'interests': ['Holy Grail', 'African Swallows']})
# OperationResult<RC=0x0, Key=u'u:king_arthur', CAS=0xb1da029b0000>

print(cb_coll.get('u:king_arthur').content_as[str])
# {u'interests': [u'Holy Grail', u'African Swallows'], u'name': u'Arthur', u'email': u'kingarthur@couchbase.com'}

## The CREATE PRIMARY INDEX step is only needed the first time you run this script
cluster.query_indexes().create_primary_index('bucket-name')

row_iter = cluster.query('SELECT name FROM bucket-name WHERE $1 IN interests', QueryOptions(positional_parameters=['African Swallows']))
for row in row_iter: print(row)
# {u'name': u'Arthur'}

完整错误如下所示:

Traceback (most recent call last):
  File "/Users/uriel/Desktop/YiL/couchbase/couchbase.py", line 1, in <module>
    from couchbase.cluster import Cluster, ClusterOptions, QueryOptions
  File "/Users/uriel/Desktop/YiL/couchbase/couchbase.py", line 1, in <module>
    from couchbase.cluster import Cluster, ClusterOptions, QueryOptions
ModuleNotFoundError: No module named 'couchbase.cluster'; 'couchbase' is not a package

Tags: namefromimportbucketrowcouchbaseclustercb

热门问题