ModuleNotFoundError: No module named 'couchbase.cluster'; 'couchbase' is not a package

ModuleNotFoundError: No module named 'couchbase.cluster'; 'couchbase' is not a package

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

我已经按照 couchbase sdk python 文档在我的计算机中通过 pip 安装了自制软件和 couchbase,在 macOS 上是 运行。

代码就是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  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

我发现了错误,目录名称与 couchbase 模块相同,所以 python 没有将其识别为模块