1

I have a docker django project and I want to use django-countries.

This is my requirements.txt

....
django-countries
django-cities

This is the INSTALLED_APPS in settings.py file

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'django_countries',
    ... (others)
]

When I run docker-up, I receive the below error:

docker_name  | Traceback (most recent call last):
docker_name  |   File "/app/manage.py", line 22, in <module>
docker_name  |     main()
docker_name  |   File "/app/manage.py", line 18, in main
docker_name  |     execute_from_command_line(sys.argv)
docker_name  |   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
docker_name  |     utility.execute()
docker_name  |   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 377, in execute
docker_name  |     django.setup()
docker_name  |   File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
docker_name  |     apps.populate(settings.INSTALLED_APPS)
docker_name  |   File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
docker_name  |     app_config = AppConfig.create(entry)
docker_name  |   File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 90, in create
docker_name  |     module = import_module(entry)
docker_name  |   File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
docker_name  |     return _bootstrap._gcd_import(name[level:], package, level)
docker_name  |   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
docker_name  |   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
docker_name  |   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
docker_name  | ModuleNotFoundError: No module named 'django_countries'

Any ideas?

Rhonald
  • 363
  • 5
  • 18
  • Did you run `pip install -r requirements.txt` (when you activated the local environment)? – Willem Van Onsem Nov 24 '20 at 20:32
  • Yes, my Dockerfiile has RUN pip install -r ./requirements.txt . Other dependencies are installed and working perfect (bootstrap4, etc.) and if I remove this line, the container works well. – Rhonald Nov 24 '20 at 20:34
  • Maybe you need to install a specific version in your requirements.txt? `django-countries==6.1.3` – kbdev Nov 24 '20 at 20:36
  • Tried sometime ago without much help. I tried once again now and it did not help with the issue – Rhonald Nov 24 '20 at 20:38
  • 2
    Did you add the requirements to your requirements.txt after your initial build? You may need to re-build the container if they were added after. `docker build` – kbdev Nov 24 '20 at 20:39
  • Awesome, it seem to be working. I had to remove all the images and then rebuild – Rhonald Nov 24 '20 at 20:49

1 Answers1

3

pip install django-countries-with-calling-codes