ImportError: cannot import name memoize - python

I have a little problem with project upgrade from Django 1.7.1 to 1.9.0.
Every 'RemovedInDjango20Warning' has been fixed, but one thing still left and I don't know how to deal with it.
When I'm trying to visit any page, there is always an ImportError like:
**TemplateSyntaxError at /auth/**
'crispy_forms_tags' is not a valid tag library:
ImportError raised loading crispy_forms.templatetags.crispy_forms_tags:
cannot import name memoize***
I have included {% load crispy_forms_tags %} in my template site, and added 'crispy_forms' in INSTALLED_APPS in settings.py
I tried to find any solution, but without success, before the update worked fine.
What am I doing wrong?

The reason for this error, as has been stated, is that Django dropped memoize at some point, so the version of crispy-forms you were trying to use was not working with the Django version.
Solutions include trying a different version of Django, or trying a different version of crispy-forms. If you are using an unreleased version of Django, then there may not be a version of cripsy that supports it (yet).
However, your error ("cannot import name memoize"), can show up for released versions of Django - I had that error, and a search lead me to this ticket. The issue was that i was using an old version of crispy (1.4.1), and a recent version of Django (1.11.1).
To find a version of crispy to use, you can check the github release page:
https://github.com/django-crispy-forms/django-crispy-forms/releases
The release comments include some information about the Django version supported by different releases.

Related

Upgrading to Django 3.0: 'django.contrib.admin.templatetags.admin_static': cannot import name 'RemovedInDjango30Warning'

My project was created with Django 2.2 and I would like to upgrade it to use 3. My problem is the same as django error cannot import name 'RemovedInDjango30Warning' . The accepted answer is to manually edit files in the Python packages which I don't think is a good practice(?). The other answers say to downgrade, so is there really no way to upgrade the project without creating it from scratch?
The file where that error is coming from has been removed in Django 3 (https://github.com/django/django/tree/3.0/django/contrib/admin/templatetags has no admin_static.py), so you might not have upgraded properly.
Try to delete your virtualenv and re-create it from scratch.

Django 1.9.13 complains SubfieldBase is deprecated, but I'm not using it. How to resolve?

I am upgrading an old Django project from Django 1.8.3 to the current Django 1.11, but to be cautious, I am upgrading to each major release of Django along the way, so I can find errors & deprecations and fix them before taking the next step. (I haven't touched this code in almost two years, so I'm a little rusty; forgive me if I'm making a simple mistake.)
I first upgraded to Django 1.9.13 (the last before 1.10), and when I manage.py runserver, I get this error:
/Users/mboszko/.virtualenvs/opticaldev/lib/python2.7/site-packages/django/utils/six.py:808: RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
return meta(name, bases, d)
If I'm reading this error right, the error stems from the custom version of six that Django embeds. I have searched my code, and I don't seem to be using SubfieldBase anywhere in my own code. (I have also googled, with not much success, for this particular error in six.)
Is this just a situation where I should upgrade to Django 1.10, and the new version of six in that package will be compatible, or is there something that I need to resolve myself before I upgrade?
Ahaaaa. Nothing like posting your question to jog a thought that leads you to the answer.
I realized I should dig deeper into the error:
$ python -Werror manage.py runserver
With that stack trace, I get a line showing:
File "/Users/mboszko/.virtualenvs/opticaldev/lib/python2.7/site-packages/django_date_extensions/fields.py", line 99, in
class ApproximateDateField(with_metaclass(models.SubfieldBase, models.CharField)):
So, the use of SubfieldBase is actually inside a package, I had installed, django-date-extensions. This was at 1.1.0 in my virtualenv, and once I did pip install --upgrade django-date-extensions to bring it up to 2.0, the error disappears.
Fixed!

TemplateSyntaxError Caught ImportError while rendering: cannot import name prepare_lookup_value

I'm pretty new to Python (2.7) and Django (1.3.1) and I'm not sure where what the next step for debugging this issue should be. A little background, this app is running just fine in my production environment which is on an EC2 instance running Ubuntu. I'm having trouble getting it running on my dev machine running Mountain Lion. I've followed what seems like standard practice and used virtualenv to keep everything properly sandboxed.
The error is happening when trying to render this pretty innocuous line:
<meta property="facebook:login_url" content="{% url socialauth_begin 'facebook' %}" />
The exception being thrown:
Exception Value: Caught ImportError while rendering: cannot import name prepare_lookup_value
Exception Location: /dev/Sites/whattest/env/lib/python2.7/site-packages/grappelli/views/related.py in <module>, line 15
line 15: from django.contrib.admin.util import prepare_lookup_value
I assume that it's a path problem of some kind but I'm at a loss for where / how to track it down at this point.
The current version of django-grappelli is compatible with Django 1.4 and 1.5; so I assume django.contrib.admin.util.prepare_lookup_value, which is being imported by django-grapelli, is simply not available in Django 1.3.
And in any case, I don't see why anybody would start something new with an such old version of Django, unless it was for legacy reasons.
UPDATE: actually, this precise issue does not seem to be the case—prepare_lookup_value was introduced in 2011 and 1.3 was released in 2013, deciding by git blame. However, the location of that function has changed from django.contrib.{util to utils}, and your code is trying to import django.contrib.admin.util.prepare_lookup_value.
Since you seem to be using old versions of (at least some) packages, I'd suggest upgrading all packages (incl. django-grapelli) in your venv to their latest versions and seeing if the problem persists.

Python can't find library but pycharm can

I recently added a yandex-maps application to my django project, fulfilling all the installation instructions. However, when I try to open the page with {% load yandex_maps_tags %} tag, I get an error:
TemplateSyntaxError: 'yandex_maps_tags' is not a valid tag library: ImportError raised loading yandex_maps.templatetags.yandex_maps_tags: Could not find the GEOS library (tried "geos_c", "GEOS"). Try setting GEOS_LIBRARY_PATH in your settings.
I didn't install a custom version of GEOS library, I didn't install it at all. However, when I click on the import line in yandex-maps library and press ⌘-B, I'm taken to GEOS's library __init__.py file, which is located at /Library/Python/2.7/site-packages/django/contrib/gis/geos/__init__.py. I don't know what is supposed to be a standard path for this library, but it looks like it to me.
I'm completely lost with this error. What can I do about it?
In order to use django.contrib.gis.geos you need first install GEOS library. Here are the instructions.
If you'll still have problems, see Can’t find GEOS library django docs.
Hope that helps.

I have trouble installing the django-socialregistration app!

I'm a Django amateur, and have problems getting django-registration to work. I followed the installation instructions on their website, but for someone like me these instructions are not 100% clear as to what I should be doing. Here is what I've done:
I installed the oauth2 and python-openid packages using pip. I then copied the facebook.py file from the facebook-python-sdk package to my main django app directory. (As I write this, I'm wondering whether this file should be copied to the socialregistration app directory? Does it make a difference?)
I copied the socialregistration directory to my django project's directory.
I added socialresgitration to my INSTALLED_APPS setting.
To add socialregistration.urls to my urls.py file, I added the following line (not sure if this is correct, since the instructions don't give details):
(r'^social/', include('socialregistration.urls')),
I added the facebook API key and secret key to my settings
I added socialregistration.auth.FacebookAuth to AUTHENTICATION_BACKENDS.
I added socialregistration.middleware.FacebookMiddleware to MIDDLEWARE_CLASSES.
Finally I added the three facebook tags they give in the instructions to one of my templates.
When I then load my website, I get the folllowing error:
Caught AttributeError while rendering: Please add the django.core.context_processors.request context processors to your settings.TEMPLATE_CONTEXT_PROCESSORS set
So, what can I do? I thought installation would be quite simple, but apparently this is not the case. ANY help would be appreciated!
Oh, BTW, I'm using Django 1.2.1 and Python 2.6.
Thanks!
Please add the django.core.context_processors.request context processors to your settings.
Have you done that?
You'll need to change TEMPLATE_CONTEXT_PROCESSORS to include django.core.context_processors.request.
I've found the problem. When my view renders the template, it needs to pass the RequestContext to the template.
return render_to_response('my_template.html', my_data_dictionary, context_instance=RequestContext(request))
Source: http://lincolnloop.com/blog/2008/may/10/getting-requestcontext-your-templates/

Categories

Resources