【问题标题】:from arango import ArangoClient ImportError: cannot import name ArangoClient从 arango import ArangoClient ImportError:无法导入名称 ArangoClient
【发布时间】:2021-12-26 19:59:51
【问题描述】:

我正在尝试运行一个在 arangodb 中发布数据的 python 脚本。 但是在运行脚本时我遇到了错误 Arangodb 在我的 localhost 中成功运行。

from arango import ArangoClient

# Initialize the ArangoDB client.
client = ArangoClient(hosts='http://192.168.0.34:8529')#IP OF THE WIFI

# Connect to "_system" database as root user.
# This returns an API wrapper for "_system" database.
sys_db = client.db('_system', username='root', password='ashu1995')

# Create a new database named "test" if it does not exist.
if not sys_db.has_database('test'):
    sys_db.create_database('test')

# Connect to "test" database as root user.
# This returns an API wrapper for "test" database.
db = client.db('test', username='root', password='ashu1995')########

# Create a new collection named "students" if it does not exist.
# This returns an API wrapper for "students" collection.
if db.has_collection('students'):
    students = db.collection('students')
else:
    students = db.create_collection('students')

# Add a hash index to the collection.
students.add_hash_index(fields=['name'], unique=False)

# Truncate the collection.
students.truncate()

# Insert new documents into the collection.
students.insert({'name': 'jane', 'age': 19})
students.insert({'name': 'josh', 'age': 18})
students.insert({'name': 'jake', 'age': 21})

# Execute an AQL query. This returns a result cursor.
cursor = db.aql.execute('FOR doc IN students RETURN doc')

# Iterate through the cursor to retrieve the documents.
student_names = [document['name'] for document in cursor]

【问题讨论】:

    标签: python-3.x arangodb pyarango


    【解决方案1】:

    确保安装了python-arango 包,而不是arango 包。

    【讨论】:

    • python-arango 7.2.0 使用 pip list 后
    猜你喜欢
    • 2012-08-20
    • 2017-11-13
    • 1970-01-01
    • 2022-01-22
    • 2021-06-30
    • 2020-10-19
    • 2018-08-13
    • 2015-01-26
    • 2020-10-10
    相关资源
    最近更新 更多