A few months ago I was working on a project with Django 1.6.5 , Django-Select2 4.3.1 and Python 2.7 but they asked me to pass it to Django 1.9
y Python 3.4
(I didn't use virtualenvs, so everything was global to the system (installed with pip)).
Then I had to start using a virtualenv for the new project and I have not been able to move forward since it does not recognize the package Django_Select2
, I have tried installing from the same origin and from others but it has not been possible.
This is part of my file settings.py
:
AUTO_RENDER_SELECT2_STATICS = False
SELECT2_BOOTSTRAP = True
SHARED_APPS = [
'tenant_schemas', # obligatoria
...
'django_select2',
...
]
TENANT_APPS = [
'tenant_schemas', # obligatoria
...
'django_select2',
...
]
And I have some forms that have this part in the header:
from django_select2 import Select2MultipleWidget, Select2Widget
This would be part of the file forms.py
:
class ActividadForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ActividadForm, self).__init__(*args, **kwargs)
todos = Persona.objects.all()
...
class Meta:
model = Actividad
exclude = ('programador', 'estado_ejecucion', 'estado_revision')
widgets = {
'ejecutor': Select2Widget(),
'revisor': Select2Widget(),
...
'beneficiarios_contratistas': Select2MultipleWidget(),
...
}
If I type in the terminal python manage.py check
this is what I get:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/commands/check.py", line 51, in handle
include_deployment_checks=include_deployment_checks,
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/checks/urls.py", line 19, in check_resolver
for pattern in resolver.url_patterns:
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/carolina/Documentos/djcode/python3_virtual/proyectos/ripso_py3d19/ripso_v2/ripso_v2/urls.py", line 39, in <module>
url(r'^agenda/', include('agenda.urls')),
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/home/carolina/Documentos/djcode/python3_virtual/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/carolina/Documentos/djcode/python3_virtual/proyectos/ripso_py3d19/ripso_v2/agenda/urls.py", line 5, in <module>
from agenda import views
File "/home/carolina/Documentos/djcode/python3_virtual/proyectos/ripso_py3d19/ripso_v2/agenda/views.py", line 9, in <module>
from agenda.forms import *
File "/home/carolina/Documentos/djcode/python3_virtual/proyectos/ripso_py3d19/ripso_v2/agenda/forms.py", line 6, in <module>
from django_select2 import Select2MultipleWidget, Select2Widget
ImportError: cannot import name 'Select2MultipleWidget'
Could you please help me to solve this problem? (or indicate another way to use another select2
if it is the case) any information not exposed here is requested.
If you are using the latest version of django-select2 you should change the import in your forms to the following:
I hope that is your help.