Question

ModuleNotFoundError: No module named 'phonenumber_field'

I’m having issues deploying my django app because it doesn’t seem to like my external packages. I get the following error logs:

[...] [...] => Initializing build
[...] [...] => Retrieving source code to /workspace
[...] [...] => Selecting branch "main"
[...] [...] => Checking out commit "b4289e792024ae1cb4cdaba8b8bf358fee562e2a"
[...] [...] => Got source_dir: /
[...] [...] => Using workspace root /workspace
[...] [...] 
[...] [...] => Building app using buildpacks
[...] [...] => Running buildpack detection
[...] [...] 
[...] [...] 3 of 4 buildpacks participating
[...] [...] digitalocean/python-appdetect 0.0.2
[...] [...] heroku/python                 0.205.4
[...] [...] digitalocean/procfile         0.0.3
[...] [...] 
[...] [...] For documentation on the buildpacks used to build your app, please see:
[...] [...]    Python: https://do.co/apps-buildpack-python
[...] [...] 
[...] [...] => Building app
[...] [...] 
[...] [...] -----> Using Python version specified in Pipfile.lock
[...] [...] -----> Installing python-3.9.9
[...] [...] -----> Installing pip 21.3.1, setuptools 57.5.0 and wheel 0.37.0
[...] [...] -----> Installing dependencies with Pipenv 2020.11.15
[...] [...]        Installing dependencies from Pipfile.lock (bd3930)...
[...] [...] -----> Installing SQLite3
[...] [...] -----> $ python manage.py collectstatic --noinput
[...] [...]        Traceback (most recent call last):
[...] [...]          File "/workspace/manage.py", line 22, in <module>
[...] [...]            main()
[...] [...]          File "/workspace/manage.py", line 18, in main
[...] [...]            execute_from_command_line(sys.argv)
[...] [...]          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
[...] [...]            utility.execute()
[...] [...]          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 420, in execute
[...] [...]            django.setup()
[...] [...]          File "/app/.heroku/python/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
[...] [...]            apps.populate(settings.INSTALLED_APPS)
[...] [...]          File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
[...] [...]            app_config = AppConfig.create(entry)
[...] [...]          File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/config.py", line 228, in create
[...] [...]            import_module(entry)
[...] [...]          File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
[...] [...]            return _bootstrap._gcd_import(name[level:], package, level)
[...] [...]          File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
[...] [...]          File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
[...] [...]          File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
[...] [...]        ModuleNotFoundError: No module named 'phonenumber_field'
[...] [...] 
[...] [...]  !     Error while running '$ python manage.py collectstatic --noinput'.
[...] [...]        See traceback above for details.
[...] [...] 
[...] [...]        You may need to update application code to resolve this error.
[...] [...]        Or, you can disable collectstatic for this application:
[...] [...] 
[...] [...]           $ heroku config:set DISABLE_COLLECTSTATIC=1
[...] [...] 
[...] [...]        https://devcenter.heroku.com/articles/django-assets
[...] [...] ERROR: failed to build: exit status 1
[...] [...] 
[...] [...] For documentation on the buildpacks used to build your app, please see:
[...] [...]    Python: https://do.co/apps-buildpack-python
[...] [...] 
[...] [...]  ! Build failed (145)

I’ve been following this Deploy a Django App on App Platform tutorial and don’t really see any important differences in my project and the tutorial. I’ve added the necessary requirements.txt file (it’s in the root directory) and don’t really have any other leads on what the issue could be.

I’ve triple-checked everything and nothing seems to be out of the ordinary. Also, it’s worth noting that I’ve tested the python manage.py collectstatic --noinput command locally and everything works fine there. I also have no real way of debugging since everything works fine locally and only fails when trying to deploy to DigitalOcean. Any suggestions?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Have you installed the django-phonenumber-field module? It should be defined in your Pipfile in order for the App platform to install it.

What you could do is to install it locally (eg pip install django-phonenumber-field), and then commit the Pipfile.lock to GitHub so that the App Platform could pick it from there.

Best,

Bobby