I'm trying to learn to work with Neo4jdatabase in my django projects. I installed Neo4Django from github repository. and following its neo4j tutorial when I try to create a new object from my model I encounter with this error:
KeyError: 'GremlinPlugin'
I'm using Python 2.7, Django Version 1.5.8, Pycharm 3
My model is:
class Movie(models.NodeModel):
# name of the movie
title = models.StringProperty()
and my console code for creating the object is:
from nodes_app.models import Movie
movie = Movie.objects.create(title='a')
and this is the console output for the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\manager.py", line 43, in create
return self.get_query_set().create(**kwargs)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\query.py", line 1307, in create
return super(NodeQuerySet, self).create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\query.py", line 416, in create
obj.save(force_insert=True, using=self.db)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 325, in save
return super(NodeModel, self).save(using=using, **kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 341, in save_base
self._save_neo4j_node(using)
File "<string>", line 2, in _save_neo4j_node
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 98, in trans_method
ret = func(*args, **kw)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 369, in _save_neo4j_node
typesToIndex=type_names_to_index)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 179, in gremlin_tx
return self.gremlin(script, tx=True, **params)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 127, in gremlin
ext = self.extensions.GremlinPlugin
File "C:\Python27\lib\site-packages\neo4jrestclient\client.py", line 2176, in __getattr__
self._dict[attr] = ExtensionModule(self._extensions[attr], self._auth)
KeyError: 'GremlinPlugin'
It seems that the Neo4j Django driver depends on the Gremlin plugin on the Neo4j server. Starting with Neo4j 2.0, Gremlin has been removed from the distribution but is still available as a contribution package, see the instructions there.
Related
I deployed one simple project on Google App Engine and there the project is working. Before I was able to get list of users from datastore through the remote API console , but now this no longer works. To start the remote API console I'm connecting this way (running from the project directory):
../../+/google_appengine_PYTHON_SDK/remote_api_shell.py -s project.appspot.com
I found that the easiest way to load all modules is to run:
s~project> help()
help>modules
help>quit
After that I try to get the list of users:
s~project> from app.models import User
s~project> User.query().fetch()
The last row results in this:
WARNING:root:suspended generator _run_to_list(query.py:964) raised RuntimeError(working outside of application context)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/utils.py", line 142, in positional_wrapper
return wrapped(*args, **kwds)
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/query.py", line 1187, in fetch
return self.fetch_async(limit, **q_options).get_result()
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/tasklets.py", line 368, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/query.py", line 964, in _run_to_list
batch = yield rpc
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/tasklets.py", line 454, in _on_rpc_completion
result = rpc.get_result()
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/api/apiproxy_stub_map.py", line 613, in get_result
return self.__get_result_hook(self)
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/datastore/datastore_query.py", line 3014, in __query_result_hook
self.__results = self._process_results(query_result.result_list())
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/datastore/datastore_query.py", line 3047, in _process_results
for result in results]
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/datastore/datastore_rpc.py", line 185, in pb_to_query_result
return self.pb_to_entity(pb)
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/model.py", line 662, in pb_to_entity
entity = modelclass._from_pb(pb, key=key, set_key=False)
File "/home/krasen/Programs/+/google_appengine_PYTHON_SDK/google/appengine/ext/ndb/model.py", line 3119, in _from_pb
ent = cls()
File "app/models.py", line 68, in __init__
if self.email == current_app.config['MAIL_ADMIN']:
File "/home/krasen/Programs/workspacePycharm/0010_1user_profile/venv/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "/home/krasen/Programs/workspacePycharm/0010_1user_profile/venv/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
return self.__local()
File "/home/krasen/Programs/workspacePycharm/0010_1user_profile/venv/local/lib/python2.7/site-packages/flask/globals.py", line 34, in _find_app
raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context
I'm very new to python. I found http://kronosapiens.github.io/blog/2014/08/14/understanding-contexts-in-flask.html but couldn't understand from this how to start working inside the app context.
I have tried on linux with python versions:
2.7.6(on clean installed linux)
2.7.9
I have tried with google app engine SDK versions:
1.9.17
1.9.23
1.9.24
The problem was in the User class itself. There I have:
def __init__(self, **kwargs):
super(User, self).__init__(**kwargs)
# FLASKY_ADMIN configuration variable, so as soon as that email address appears in a registration request it can be given the correct role
if self.role is None:
print ("there is no role for this user")
if self.email == current_app.config['MAIL_ADMIN']:
self.role = ndb.Key('Role', 'administrator')
the problematic line is this line:
if self.email == current_app.config['MAIL_ADMIN']:
I don't know how to manage to make it work with this line so I've removed it and now the user is retrieved.
I'm trying to add django-seo into my site. But I can't cope with setting up. I followed instructions documentation, but error occurs.
This is what I did:
Installed django-seo packacge
Added rollyourown.seo to INSTALED_APPS
Created seo.py file in my site content app
And this is what I wrote into seo.py file:
from rollyourown import seo
class Metadata(seo.Metadata):
title = seo.Tag(head=True, max_length=68)
description = seo.MetaTag(max_length=155)
keywords = seo.KeywordTag()
heading = seo.Tag(name="h1")
class Meta:
seo_views = ('SiteContent',)
seo_models = ('SiteContent',)
When Meta class is removed, I can't add any meta tags to contnet via Django Admin Site( I registered it in admin site ). I've read that django-seo use get_absolute_url() to deal with it. But in my site app I don't use this function for provide more some utilities to multilanguage.
But if i add Meta class, i will get this error:
Traceback (most recent call last):
File "F:/Site/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "F:\Python27\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "F:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "F:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\models.py", line 10, in <module>
__import__(module_name)
File "F:\Site\SiteContent\seo.py", line 5, in <module>
class Metadata(seo.Metadata):
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\base.py", line 166, in __new__
options = Options(Meta, help_text)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 19, in __init__
self._set_seo_models(meta.pop('seo_models', []))
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 96, in _set_seo_models
seo_models.extend(models.get_models(app))
File "F:\Python27\lib\site-packages\django\db\models\__init__.py", line 54, in alias
return getattr(loading, function_name)(*args, **kwargs)
File "F:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I tried diffrent solutions but nothing helped.
Django-SEO is not compatible with Django 1.7, which is the first version of Django that includes the AppRegistry.
Either rollback to Django 1.6.x or remove Django-SEO.
I got it working by changing get_query_set() to get_queryset()(changed in django1.8) in file rollyourown\seo\backends.py
As original Django-SEO is not supported anymore, these guys made and support their own version / fork of Django-SEO. I use it with Django 1.8.8, Python 3 is supported too.
https://github.com/whyflyru/django-seo
I'm trying to use celery 3.1.0 with Django 1.6. I've gone through this tutorial but once I call celery using the method it describes (celery -A proj worker -l info) I get the following error:
Traceback (most recent call last):
File "/Users/dustin/.virtualenvs/proj_env/bin/celery", line 9, in <module>
load_entry_point('celery==3.1.0', 'console_scripts', 'celery')()
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/__main__.py", line 29, in main
main()
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/celery.py", line 80, in main
cmd.execute_from_commandline(argv)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/celery.py", line 732, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/base.py", line 299, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/base.py", line 429, in setup_app_from_commandline
self.app = self.find_app(app)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/base.py", line 463, in find_app
'{0}.celery:'.format(app.replace(':', '')),
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/base.py", line 449, in find_app
sym = self.symbol_by_name(app)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/bin/base.py", line 474, in symbol_by_name
return symbol_by_name(name, imp=import_from_cwd)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/kombu/utils/__init__.py", line 90, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/dustin/src/myco/proj/proj/celery.py", line 13, in <module>
app.autodiscover_tasks(settings.INSTALLED_APPS, related_name='tasks')
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/app/base.py", line 277, in autodiscover_tasks
if self.conf.CELERY_FORCE_BILLIARD_LOGGING:
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/datastructures.py", line 336, in __getattr__
return self[k]
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/celery/datastructures.py", line 458, in __getitem__
return d[key]
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/django/utils/functional.py", line 214, in inner
return func(self._wrapped, *args)
File "/Users/dustin/.virtualenvs/proj_env/lib/python2.7/site-packages/django/utils/functional.py", line 263, in __getitem__
return self[key]
TypeError: 'Settings' object has no attribute '__getitem__'
Has anyone encountered this before? What am I missing?
I fixed this error by binding my celery package to the version that works with my django application.
Those were the versions that throw the error
celery # the newest
celery==3.1 # main version before the newest
This is the version that worked for me
celery==3.1.25 # the last working version with my app
i used celery==3.1.25 to fix the problem
Celery == 3.1 django == 1.10 django-celery == 3.1.17
This version doesn't work well
I'm trying to add a nice admin interface to an existing Pyramid project. I created a test project using pcreate -s alchemy -s pyramid_fa fa_test and then copied all the extra files created into my project and altered them to be suitable.
Everything looks to be good and dandy until I try to add a formalchemy route:
config.formalchemy_model("/foo", package='bar',
model='bar.models.specific_models.Thingy',
**settings)
Then I get: ImportError: No module named forms
My question is: How do I fix this? Or what is the correct way to add an admin interface?
I've googled around a bunch to no avail...
Here's relevant code:
fainit.py:
from bar import models, faforms
import logging
def includeme(config):
config.include('pyramid_formalchemy')
config.include('bar.fainit')
config.include('fa.jquery')
config.include('pyramid_fanstatic')
model_view = 'fa.jquery.pyramid.ModelView'
session_factory = 'bar.models.access.DBSession'
## register session and model_view for later use
settings = {'package': 'bar',
'view': model_view,
'session_factory': session_factory,
}
config.registry.settings['bar.fa_config'] = settings
config.formalchemy_admin("/admin", models=models, forms=faforms,
**settings)
# Adding the package specific routes
config.include('shop.faroutes')
log.info('formalchemy_admin registered at /admin')
faroutes.py
from bar import models
import logging
log = logging.getLogger(__name__)
def includeme(config):
settings = config.registry.settings.get('shop.fa_settings}}', {})
config.formalchemy_model("/alerts", package='shop',
model='shop.models.super_models.Alert',
**settings)
log.info('shop.faroutes loaded')
And the traceback:
Starting subprocess with file monitor
Traceback (most recent call last):
File "../bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5a1', 'console_scripts', 'pserve')()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 316, in run
global_conf=vars)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 340, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/home/sheena/WORK/tv_guys_env/shop/shop/__init__.py", line 30, in main
includeme(config)
File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 8, in includeme
config.include('shop.fainit')
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
c(configurator)
File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 24, in includeme
config.include('shop.faroutes')
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
c(configurator)
File "/home/sheena/WORK/tv_guys_env/shop/shop/faroutes.py", line 12, in includeme
**settings)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/util.py", line 507, in wrapper
result = wrapped(self, *arg, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 58, in formalchemy_model
view=view, models=[model], model=model, **kwargs)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 85, in formalchemy_admin
forms = config.maybe_dotted('%s.forms' % package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 848, in maybe_dotted
return self.name_resolver.maybe_resolve(dotted)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 316, in maybe_resolve
return self._resolve(dotted, package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 323, in _resolve
return self._zope_dottedname_style(dotted, package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 372, in _zope_dottedname_style
__import__(used)
ImportError: No module named forms
It sounds like it's looking for you to create a forms module at shop.faroutes.forms.
I'm going through Django tutorial and using PyDev Eclipse plugin for development.
For interactive testing I use "Interactive shell with Django" which is accessed by Right click on PyDev project -> Django -> Shell with Django environment.
And here is the problem I encountered ("lemonanas" is my project name, "polls" is my app name):
>>from lemonanas.polls.models import Poll, Choice
>>Poll.objects.filter(id=1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "F:\Python27\lib\site-packages\django\db\models\manager.py", line 141, in filter
return self.get_query_set().filter(*args, **kwargs)
File "F:\Python27\lib\site-packages\django\db\models\query.py", line 561, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "F:\Python27\lib\site-packages\django\db\models\query.py", line 579, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1170, in add_q
can_reuse=used_aliases, force_having=force_having)
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1058, in add_filter
negate=negate, process_extras=process_extras)
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1225, in setup_joins
field, model, direct, m2m = opts.get_field_by_name(name)
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 296, in get_field_by_name
cache = self.init_name_map()
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 326, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 401, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 415, in _fill_related_many_to_many_cache
for klass in get_models():
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 167, in get_models
self._populate()
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 76, in load_app
app_module = import_module(app_name)
File "F:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named polls
If I use default shell, executing "manage.py shell" - all works fine. But default shell not such comfortable as "Interactive shell with Django".
I noticed that "Interactive shell with Django" does not add my app folder (polls) to python path. And I guess this is the essense of problem. But don't know how to entirely solve all "import/pythonpath/etc." problems with "Interactive shell with Django".
Hope you can help me.
Thanks.
Customize the python path, eclipse uses to include the path to the project. (Not each app, just the project folder. - The one that contains settings.py)
In Eclipse, right click your project, goto PyDev-> Set as source folder