2011-06-17 78 views
8

我正在使用neo4j的django集成,並且在嘗試創建節點時出現以下回溯。
我有JPype安裝,它可以導入。在neo4j中創建對象的問題

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. 
} 

編輯:


以下大袍的建議,我碰到下面的,當我試圖導入我自己的模型後,
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' 
+0

你可以提供你的neo4j配置在你的django settings.py? – 2011-06-20 20:49:38

+0

@FelipeCruz:是的,我會今天做 – 2011-06-21 06:03:59

回答

1

您的settings.py看起來不錯..

您是否已經安裝了java SDK並將JAVA_HOME環境變量設置爲您的JDK? (的Java JRE是不夠的)

從Neo4j.py文檔:

In some situations the JPype compilation process might not link with the appropriate JNI headers, resulting in compilation errors. The first thing to note is that JPype needs the JNI headers from a JDK in order to build, it is not enough to only have a JRE installed when building JPype. If the JAVA_HOME environment variable is not set when building JPype the build script (setup.py) of JPype might have problems locating the appropriate JNI headers. If you are building JPype with sudo python setup.py install you might not inherit the JAVA_HOME environment variable into the sudo environment, an easy warkaround is to run python setup.py bdist before install.

2

您可以通過添加這NEO4J_OPTIONS獲取有關爲何後端無法找到更詳細的信息:

NEO4J_OPTIONS = { 
    log: True, 
} 

該日誌記錄的輸出將更容易診斷實際問題並提出修復建議。

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" 

所在的路徑是您要使用的JDK的位置(它應該有文件夾/斌之後它與java和javac程序)

我還試過的是添加位置/etc/bash.bashrc。哪些不適合我,但可能適合你。

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

無論如何,這應該讓你開始正確的方向。但現在我有另一個相關的問題,我堅持一個星期沒有答案:(