geodjango with mysql database - python

I am developing an application with geodjango and I have been running into some difficulties. following the procedures on the official django website https://docs.djangoproject.com/en/1.11/ref/contrib/gis/tutorial/#use-ogrinfo-to-examine-spatial-data . I first used the orginfo to check spatial data I got a failed message
FAILURE:
Unable to open datasource `world/data/TM_WORLD_BORDERS-0.3.shp' with the following drivers.
then I followed the remaining process creating the models and the error I got when I ran migration was
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/Olar/Desktop/arbithub/src/geolocation/models.py", line 5, in <module>
from django.contrib.gis.db import models
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
from django.contrib.gis.db.models.aggregates import * # NOQA
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/aggregates.py", line 1, in <module>
from django.contrib.gis.db.models.fields import ExtentField
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/forms/fields.py", line 4, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/geos/__init__.py", line 18, in <module>
HAS_GEOS = geos_version_info()['version'] >= '3.3.0'
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/geos/libgeos.py", line 196, in geos_version_info
raise GEOSException('Could not parse version info string "%s"' % ver)
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.6.2-CAPI-1.10.2 4d2925d6"
.
further codes would b supplied based on request. Kindly help with it

The Could not parse version info string error is the issue in ticket 28441, which has been fixed in Django 1.11.5.
Note that it's always a good idea to use the latest point release (currently 1.11.5 for 1.11.X) to make sure you've got the latest security patches and bug fixes.

Related

AttributeError: 'Settings' object has no attribute 'OSCAR_REQUIRED_ADDRESS_FIELDS'

i have this issue in django oscar when i execute python manage.py migrate i am a beginner in django oscar .any help and suggestions are welcome.
below is my error message.
#localhost production1]$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/oscar/apps/address/models.py", line 1, in <module>
from oscar.apps.address.abstract_models import (
File "/usr/lib/python2.7/site-packages/oscar/apps/address/abstract_models.py", line 19, in <module>
class AbstractAddress(models.Model):
File "/usr/lib/python2.7/site-packages/oscar/apps/address/abstract_models.py", line 35, in AbstractAddress
POSTCODE_REQUIRED = 'postcode' in settings.OSCAR_REQUIRED_ADDRESS_FIELDS
File "/usr/lib64/python2.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'OSCAR_REQUIRED_ADDRESS_FIELDS'
by docs
The last addition to the settings file is to import all of Oscar’s default settings:
from oscar.defaults import *
more details install-by-hand, hope it help you

Upgrading to Django 1.7: Getting AppRegistryNotReady for translation infrastructure

I'm upgrading from Django 1.6 to 1.7 and when I try to do manage.py runserver I get the following trace:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ben/Code/Repos/myrepo/myproject/core/mail/__init__.py", line 6, in <module>
from myproject.core.mail.models import IMapEmailMessage, EmailStatus
File "/home/ben/Code/Repos/myrepo/myproject/core/mail/models.py", line 20, in <module>
from myproject.core.mail.utils import render_templates
File "/home/ben/Code/Repos/myrepo/myproject/core/mail/utils.py", line 19, in <module>
from myproject.core.util import clean_html
File "/home/ben/Code/Repos/myrepo/myproject/core/util.py", line 1031, in <module>
def make_url(url, text=_('here')):
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 83, in ugettext
return _trans.ugettext(message)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 325, in ugettext
return do_translate(message, 'ugettext')
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 306, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 209, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 189, in _fetch
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
I haven't used the app registry before, so I assume some setup needs to be done in my apps before translations can be used. The solution I keep seeing is to add this to wsgi.py:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
However I already have those lines in there. In the file myproject/core/util.py I changed the following line:
from django.utils.translation import ugettext as _
to:
from django.utils.translation import ugettext_lazy as _
And that just moved the issue to another file which used ugettext. Is it no longer possible to use non-lazy ugettext? Or is there some setup I need to do to avoid it being evaluated at import time?
The problem with using make_url(url, text=ugettext('here')) is that the default argument for text is evaluated when the module is imported, not when the make_url function runs.
You haven't shown the code that generated the second error, so I don't know what was wrong with it.
It is fine to use ugettext inside a function (as long as that function doesn't run during import time). For example:
def make_url(url, text=None):
if text is None:
text = ugettext('here')
Note, you can still do import uggettext as _ in your code, I've just used ugettext above to be explicit.

Django won't start with a wierd error "AttributeError: 'module' object has no attribute 'getargspec'"

I'm a bit inexperienced when it comes to Django's internals so I'm completely stuck now. It worked yesterday, and I can't remember I've changed anything significant.
When I turn DEBUG=True there is a stack trace on any module which happens to be first in the list
Traceback (most recent call last):
File "/home/yury/PycharmProjects/mezzamine/findmeals/mezzamine/manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/usr/local/lib/python3.4/dist-packages/django/utils/log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/local/lib/python3.4/dist-packages/django/http/__init__.py", line 4, in <module>
from django.http.response import (
File "/usr/local/lib/python3.4/dist-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/base.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python3.4/dist-packages/django/db/__init__.py", line 98, in <module>
signals.request_started.connect(reset_queries)
File "/usr/local/lib/python3.4/dist-packages/django/dispatch/dispatcher.py", line 99, in connect
argspec = inspect.getargspec(receiver)
AttributeError: 'module' object has no attribute 'getargspec'
And when I turn DEBUG=False it complains about
Traceback (most recent call last):
File "/home/yury/PycharmProjects/mezzamine/findmeals/mezzamine/manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/usr/local/lib/python3.4/dist-packages/django/utils/log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/local/lib/python3.4/dist-packages/django/http/__init__.py", line 4, in <module>
from django.http.response import (
File "/usr/local/lib/python3.4/dist-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/base.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python3.4/dist-packages/django/db/models/__init__.py", line 8, in <module>
from django.db.models.manager import Manager # NOQA
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 63, in <module>
class BaseManager(six.with_metaclass(RenameManagerMethods)):
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 778, in __new__
return meta(name, bases, d)
File "/usr/local/lib/python3.4/dist-packages/django/utils/deprecation.py", line 50, in __new__
for base in inspect.getmro(new_class):
AttributeError: 'module' object has no attribute 'getmro'
I use Django 1.7.8 and Mezzanine 3 and tried upgrading and reinstalling them with no luck. Could anyone give a hint on what's wrong?
You have a local file called "inspect.py" that is shadowing the stdlib module. Name your file something else.
django/utils/inspect.pyc is shadowing standard library inspect.py
django/utils/inspect.py was added in Django 1.9 and compiled binary file is left after you downgraded to 1.7.8

500 Server Error on GAE - MySQLdb not loaded

I get a 500 Server Error while uploading my app on GAE. It works perfectly fine locally with dev_appserver with SETTINGS_MODE='prod'.
Based on the logs, it cannot find MySQLdb on GAE. It does not make sense to me.
Help!
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/core/handlers/wsgi.py", line 236, in __call__
self.load_middleware()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/core/handlers/base.py", line 49, in load_middleware
mod = import_module(mw_module)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/middleware.py", line 3, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/backends.py", line 3, in <module>
from django.contrib.auth.models import Permission
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/models.py", line 8, in <module>
from django.db import models
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
The answer is fairly simple. Add the following lines in the app.yaml file:
libraries:
- name: MySQLdb
version: "latest"
Details can be found on the page
https://cloud.google.com/appengine/docs/python/cloud-sql

Django migration

I have migrated django website from live server to my localhost, i took the backup of posrgresql database and attached to my localhost i have changed the databse connection details in the live_setting.py and also installed the required packages which were already installed on the live server but i am unable to run the website on my localhost when i use manage.py ruserver command i got the following errors.
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x02BB6530>>
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 91, in inner_run self.validate(display_num_errors=True)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 266,in validate num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 158, inget_app_errors self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 67, in_populate self.load_app(app_name)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 88, in load_app models = import_module('.models', app_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module__import__(name)
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\models.py", line 8, in <module>'social_auth.db.django_models'))
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module__import__(name)
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\db\django_models.py", line 5, in <module>from social_auth.db.base import UserSocialAuthMixin, AssociationMixin, \
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\db\base.py", line 7, in <module> from openid.association import Association as OIDAssociation
File "build\bdist.win32\egg\openid\association.py", line 37, in <module>
File "build\bdist.win32\egg\openid\cryptutil.py", line 33, in <module>
File "build\bdist.win32\egg\openid\oidutil.py", line 16, in <module> ImportError: No module named parse
I am using python 2.6 and django 1.4.3, how can i solve these errors, i am new to python/django development.

Categories

Resources