pycharm链接neo4j数据库(简单)

1.安装pycharm

2.安装库

pip install py2neo -i https://pypi.tuna.tsinghua.edu.cn/simple

3.代码试运行

复制代码
from py2neo import Graph, Node, Relationship

# 连接到Neo4j数据库,使用Bolt协议
graph = Graph("bolt://localhost:7687", auth=("neo4j", "password"))

# 创建根节点
greedy_algorithm = Node("GreedyAlgorithm", name="Greedy Algorithm")

# 创建贪心算法的基本概念节点
basic_concept = Node("BasicConcept", name="基本概念")
graph.create(greedy_algorithm)
graph.create(basic_concept)

# 创建贪心算法的特点节点
features = Node("Features", name="特点")
graph.create(features)

# 创建贪心算法适用场景节点
app_scenario = Node("AppScenario", name="适用场景")
graph.create(app_scenario)

# 创建贪心算法示例节点
examples = Node("Examples", name="算法示例")
graph.create(examples)

# 创建贪心算法在优化问题中的应用节点
optimization = Node("Optimization", name="优化问题")
graph.create(optimization)

# 创建与其他算法的比较节点
comparison = Node("Comparison", name="与其他算法的比较")
graph.create(comparison)

# 创建局限性节点
limitations = Node("Limitations", name="局限性")
graph.create(limitations)

# 创建关系
graph.create(Relationship(greedy_algorithm, "INCLUDES", basic_concept))
graph.create(Relationship(greedy_algorithm, "INCLUDES", features))
graph.create(Relationship(greedy_algorithm, "INCLUDES", app_scenario))
graph.create(Relationship(greedy_algorithm, "INCLUDES", examples))
graph.create(Relationship(greedy_algorithm, "INCLUDES", optimization))
graph.create(Relationship(greedy_algorithm, "INCLUDES", comparison))
graph.create(Relationship(greedy_algorithm, "INCLUDES", limitations))

# 查询并打印结果
results = graph.run("MATCH (a:GreedyAlgorithm)-[r]->(b) RETURN a, r, b")
for record in results:
    print(record)

4.打开浏览器中的neo4j

相关推荐
AllData公司负责人16 小时前
亲测丝滑,体验跃迁|AllData通过集成开源项目Datart,让数据可视化一目了然
java·大数据·数据库·python·数据可视化·数据视图·datart
tang7778916 小时前
2026代理IP选型逻辑与成本控制:动态IP VS 静态IP、住宅IP VS 运营商IP VS 数据中心IP的深入解析
爬虫·python·代理ip·住宅ip·住宅代理·运营商ip
AI玫瑰助手16 小时前
Python函数:def定义函数与参数传递基础
android·开发语言·python
24kmaigc16 小时前
NewStarCTF2025-ssti在哪里?-ssrf与ssti注入
python·网络安全·flask·web
老虎海子16 小时前
从零手搓一个 AI 编程助手:Mini Claude Code 完全指南
人工智能·git·vscode·python·github
辞忧九千七17 小时前
吃透Redis7核心数据结构:从基础用法到实战场景(Python版)
开发语言·数据结构·redis·python
空圆小生17 小时前
基于 Python+Vue3 的 AI 人脸识别门禁考勤系统
开发语言·人工智能·python
Yoshizawa-Violet17 小时前
模板方法模式实战:重构Agent工具审批,告别重复代码
python·agent·模板方法
HjhIron17 小时前
Python列表与LLM接口实战:从切片到DeepSeek调用
python
搬砖的小码农_Sky17 小时前
macOS Sequoia上如何安装Python开发环境?
开发语言·python·macos