使用NEO4J 创建关系的时候报错AttributeError: 'NoneType' object has no attribute 'labels' #6

参考此数据集

在下面代码
https://github.com/jm199504/Financial-Knowledge-Graphs/blob/master/code/python_to_neo4j.ipynb

的这一步,报错。
matcher = NodeMatcher(graph)
for i in holder.values:
a = matcher.match("股票",TS代码=i[0]).first()
b = matcher.match("股东",TS代码=i[0])
for j in b:
r = Relationship(j,'参股',a)
graph.create(r)
print('TS',str(i[0]))

报以下错误
File "E:\Anaconda3\lib\site-packages\py2neo\data.py", line 847, in init
Entity.init(self, (n[0], self, n[1]), properties)
File "E:\Anaconda3\lib\site-packages\py2neo\data.py", line 553, in init
Walkable.init(self, iterable)
File "E:\Anaconda3\lib\site-packages\py2neo\data.py", line 453, in init
_ = node.labels # ensure not stale
AttributeError: 'NoneType' object has no attribute 'labels'

Process finished with exit code 1

是哪儿设置错误了吗?

有专家吗

如果只是让它不报错,就简单判断一下nodematcher是否为空就可以解决,如果要彻底弄清楚为什么为空,就需要看数据情况了。

是不是版本问题,你换下4.2版本py2neo

应该是你match匹配时没匹配成功的话,match()就返回None。None 的类型是NoneType , 它没有labels 方法。

解决思路
错误属性:“nonetype”对象没有“labels属性

解决方法
属性错误:非类型的,对象没有属性“labels”的方法,利用pip进行更新一下包即可!因为旧的库没有该方法。

https://blog.csdn.net/cheer6up/article/details/108417009?spm=1005.2026.3001.5635&utm_medium=distribute.pc_relevant_ask_down.none-task-blog-2~default~OPENSEARCH~Rate-4.pc_feed_download_top3ask&depth_1-utm_source=distribute.pc_relevant_ask_down.none-task-blog-2~default~OPENSEARCH~Rate-4.pc_feed_download_top3ask

img


大致翻译一下就是

文件“E:Anaconda3lliblsite-packageslpy2neoldata.py”,第847行,在init Entity。init(self, (n[O], self, n[1]), properties) File "E:Anaconda3Viblsite-packageslpy2neoldata.py",第553行,在init Walkable。init(self, iterable)文件“E:Anaconda3liblsite-packageslpy2neoldata.py”,第453行,在init = node。标签#确保不过时
AttributeError: 'NoneType'对象没有属性'labels'进程结束,退出码为1
错误就是有个创建的对象是空类型的,没有属性labels

希望对题主有所帮助!