在neo4j中创建对象的问题

时间:2011-06-17 09:49:27

标签: django neo4j neo4j.py

我正在使用django集成neo4j,当我尝试创建节点时,我得到以下回溯。
我安装了JPype,可以导入。

 p = Person.objects.create(first_name='omer', last_name='katz')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 138, in create
    return self.get_query_set().create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/model/django_model/__init__.py", line 362, in create
    obj.save(force_insert=True)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_util.py", line 47, in __get__
    method, graphdb = self.descr_get(obj, cls)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_util.py", line 41, in descr_get
    graphdb = self.accessor.__get__(obj, cls)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/model/django_model/__init__.py", line 58, in __get__
    return DjangoNeo.neo
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/model/django_model/__init__.py", line 124, in neo
    return self.__setup_neo()
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/model/django_model/__init__.py", line 136, in __setup_neo
    self.__neo = NeoService(resource_uri, **options)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/__init__.py", line 522, in __new__
    neo = core.load_neo(resource_uri, params)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_core.py", line 180, in load_neo
    backend.initialize(**parameters)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 61, in initialize
    raise ImportError("No applicable backend found.")
ImportError: No applicable backend found.

编辑:
这里要求的是我的neo4j设置:

NEO4J_RESOURCE_URI = '/var/neo4j/neo4django'
# NEO4J_RESOURCE_URI should be the path to where
#    you want to store the Neo4j database.

NEO4J_OPTIONS = {
    # this is optional and can be used to specify
    # extra startup parameters for Neo4j, such as
    # the classpath to load Neo4j from.
}

编辑:
按照thobe的建议,当我尝试导入自己的模型时,我得到以下内容:

    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      FERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    ERROR:root:Importing native backends failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
        embedded, remote = implementation.initialize(classpath, params)
      File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
        jvm = jpype.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
        return _linux.getDefaultJVMPath()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
        jvm = _getJVMFromJavaHome()
      File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
        if os.path.exists(java_home+"/bin/javac") :
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

ile "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
    embedded, remote = implementation.initialize(classpath, params)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
    jvm = jpype.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
    return _linux.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
    jvm = _getJVMFromJavaHome()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
    if os.path.exists(java_home+"/bin/javac") :
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
ERROR:root:Importing native backends failed.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
    embedded, remote = implementation.initialize(classpath, params)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
    jvm = jpype.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
    return _linux.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
    jvm = _getJVMFromJavaHome()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
    if os.path.exists(java_home+"/bin/javac") :
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
ERROR:root:Importing native backends failed.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
    embedded, remote = implementation.initialize(classpath, params)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
    jvm = jpype.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
    return _linux.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
    jvm = _getJVMFromJavaHome()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
    if os.path.exists(java_home+"/bin/javac") :
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
ERROR:root:Importing native backends failed.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/__init__.py", line 51, in initialize
    embedded, remote = implementation.initialize(classpath, params)
  File "/usr/local/lib/python2.7/dist-packages/Neo4j.py-0.1_SNAPSHOT-py2.7.egg/neo4j/_backend/reflection.py", line 44, in initialize
    jvm = jpype.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_core.py", line 96, in getDefaultJVMPath
    return _linux.getDefaultJVMPath()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 36, in getDefaultJVMPath
    jvm = _getJVMFromJavaHome()
  File "/usr/local/lib/python2.7/dist-packages/jpype/_linux.py", line 55, in _getJVMFromJavaHome
    if os.path.exists(java_home+"/bin/javac") :
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

3 个答案:

答案 0 :(得分:2)

通过将此添加到NEO4J_OPTIONS,您可以获得有关无法找到后端的详细信息:

NEO4J_OPTIONS = {
    log: True,
}

该日志记录的输出将使您更容易诊断实际问题并建议修复。

答案 1 :(得分:1)

你的settings.py看起来不错..

您是否已安装java SDK并将JAVA_HOME环境变量设置为JDK? (java JRE是不够的)

来自Neo4j.py docs:

  

在某些情况下,JPype   编译过程可能没有链接   使用适当的JNI标头,   导致编译错误。该   首先要注意的是JPype   需要来自JDK的JNI头文件   为了建立,这还不够   只有安装了JRE时   建立JPype。如果是JAVA_HOME   环境变量未设置   构建JPype构建脚本   JPype的(setup.py)可能有   找到适当的JNI的问题   头。如果你正在构建JPype   用sudo python setup.py安装你   可能不会继承JAVA_HOME   环境变量进入sudo   环境,一个简单的warkaround是   之前运行python setup.py bdist   安装。

答案 2 :(得分:1)

我遇到了同样的问题。无论我做什么(在Debian上),Python都找不到JAVA_HOME环境变量。修复它的最简单的方法,我认为你可以在Django中添加它,是添加这些行 -

java_home = os.getenv("JAVA_HOME")
if(java_home == None):
    os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-6-openjdk"

其中path是你想要使用的JDK的位置(它应该有java / javac程序之后的文件夹/ bin)

我还尝试将位置添加到/etc/bash.bashrc。哪个对我不起作用,但可能适合你。

JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

无论如何,这应该让你开始朝着正确的方向前进。但现在我有另一个相关的问题,我坚持一段时间没有答案:(