python 连接neo4j失败
发布于 6 年前 作者 arfer 7194 次浏览 来自 问答

今天写一个老师的任务 在neo4j中导入json格式的知识图谱 但总是失败在第一步连接 graph = Graph(“bolt://localhost:7687”,username=“neo4j”,password = “1234”)上 贴上代码

import json from py2neo import Node, Relationship, NodeMatcher, Graph

graph = Graph(“bolt://localhost:7687”,username=“neo4j”,password = “1234”)

with open(‘微观经济学.json’, ‘r’, encoding=‘utf-8’) as file: str = file.read() results = json.loads(str) matcher = NodeMatcher(graph) for item in results: a = matcher.match(‘object’, name=item.get(‘object’)).first() if not a: a = Node(‘object’, name = item.get(‘object’)) b = matcher.match(‘object’, name=item.get(‘subject’)).first() if not b: b = Node(‘object’, name = item.get(‘subject’))

    r = Relationship(b, item.get('relation') ,a)
    graph.create(a)
    graph.create(b)
    graph.create(r)
	
	错误截图:
	/anaconda3/python.app/Contents/MacOS/python /Users/xuefei/PycharmProjects/untitled/Arfer/neo4j/微观经济学.py

Traceback (most recent call last): File “/Users/xuefei/PycharmProjects/untitled/Arfer/neo4j/微观经济学.py”, line 4, in <module> graph = Graph(“bolt://localhost:7687”,username=“neo4j”,password = “1234”) File “/Users/xuefei/.local/lib/python3.6/site-packages/py2neo/database.py”, line 305, in new database = Database(uri, **settings) File “/Users/xuefei/.local/lib/python3.6/site-packages/py2neo/database.py”, line 85, in new connection_data = get_connection_data(uri, **settings) File “/Users/xuefei/.local/lib/python3.6/site-packages/py2neo/internal/addressing.py”, line 118, in get_connection_data data[“user_agent”] = http_user_agent() if data[“scheme”] in [“http”, “https”] else bolt_user_agent() File “/Users/xuefei/.local/lib/python3.6/site-packages/py2neo/meta.py”, line 34, in bolt_user_agent *((package, version, neo4j.version,) + tuple(version_info) + (platform,))) AttributeError: module ‘neo4j’ has no attribute ‘version

Process finished with exit code 1

2 回复

看上去感觉是py2neo包的问题,neo4j没有version属性?不太确定问题在哪,试试把py2neo删了重新装一次?仅供参考

另外配置信息这边的引号是用了英文引号么~?

谢谢 是的 是包的问题 不知道是不是跟之前默认的Anaconda环境冲突了 重新设置环境 下载py2neo就OK啦

回到顶部