Error while deploying django project to Vercel [duplicate]

I am trying to deploy a Django project to Vercel, but I am running into an issue related to distutils. During the build process, I get a ModuleNotFoundError: No module named 'distutils', and I'm unsure how to resolve this error. Below is my setup, and the build error I’m seeing.

My Vercel configuration:

In the vercel.json file, I am specifying the Django WSGI app as the entry point, along with Python as the runtime without specifying the version as its version 3.12 by default:

{
    "builds": [{
        "src": "trial_project_django/wsgi.py",
        "use": "@vercel/python",
        "config": { "maxLambdaSize": "15mb", "runtime": "python" }
    }],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "trial_project_django/wsgi.py"
        }
    ]
}

My requirements.txt file

absl-py==2.1.0
aioredis==1.3.1
asgiref==3.7.2
astunparse==1.6.3
async-timeout==4.0.3
attrs==23.2.0
autobahn==23.6.2
Automat==22.10.0
cachetools==5.3.3
certifi==2024.6.2
cffi==1.16.0
channels==4.1.0
channels-redis==2.4.2
charset-normalizer==3.3.2
constantly==23.10.4
cryptography==42.0.8
daphne==4.1.2
dj-database-url==2.1.0
Django==5.0.3
django-cors-headers==4.4.0
django-heroku==0.3.1
elastic-transport==8.15.0
elasticsearch==8.15.1
elasticsearch-dsl==8.15.3
et-xmlfile==1.1.0
flatbuffers==24.3.25
gast==0.5.4
git-filter-repo==2.38.0
google-auth==2.30.0
google-auth-oauthlib==1.2.0
google-pasta==0.2.0
grpcio==1.64.1
gunicorn==22.0.0
h5py==3.11.0
hiredis==2.3.2
hyperlink==21.0.0
idna==3.7
incremental==22.10.0
joblib==1.4.2
keras==2.15.0
libclang==18.1.1
Markdown==3.6
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
ml-dtypes==0.2.0
msgpack==0.6.2
namex==0.0.8
numpy==1.26.4
oauthlib==3.2.2
opencv-python==4.9.0.80
openpyxl==3.1.5
opt-einsum==3.3.0
optree==0.11.0
packaging==24.0
pandas==2.2.2
protobuf==4.25.3
psycopg2==2.9.9
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
pydub==0.25.1
Pygments==2.18.0
pykalman==0.9.7
pyOpenSSL==24.1.0
python-dateutil==2.9.0.post0
pytz==2024.1
redis==5.0.5
requests==2.32.3
requests-oauthlib==2.0.0
rich==13.7.1
rsa==4.9
scikit-learn==1.5.0
scipy==1.13.1
service-identity==24.1.0
six==1.16.0
sqlparse==0.4.4
tensorboard==2.15.2
tensorboard-data-server==0.7.2
tensorflow==2.15.0
tensorflow-estimator==2.15.0
tensorflow-intel==2.15.0
tensorflow-io-gcs-filesystem==0.31.0
termcolor==2.4.0
threadpoolctl==3.5.0
Twisted==24.3.0
twisted-iocpsupport==1.0.4
txaio==23.1.1
typing_extensions==4.12.0
tzdata==2024.1
urllib3==2.2.1
Werkzeug==3.0.3
whitenoise==6.6.0
wrapt==1.14.1
zope.interface==6.4.post2

Build Errors:

Here’s the build log from Vercel showing the error:

[16:40:52.957] WARN! Due to `builds` existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply.
[16:41:03.976] Failed to run "pip3.12 install --disable-pip-version-check --target . --upgrade -r /vercel/path0/requirements.txt"
[16:41:03.977] Error: Command failed: pip3.12 install --disable-pip-version-check --target . --upgrade -r /vercel/path0/requirements.txt
[16:41:03.979] ERROR: Exception:
[16:41:03.979] ModuleNotFoundError: No module named 'distutils'

The build process fails when it tries to install my project’s dependencies using pip3.12. The error seems to originate from setuptools, which tries to import distutils but can’t find it in the current Python environment. The specific error I’m seeing is:

File "/tmp/pip-build-env-h15xlab8/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 10, in <module>
  import distutils.core
ModuleNotFoundError: No module named 'distutils'

Questions: How can I resolve the ModuleNotFoundError: No module named 'distutils' on Vercel during the build process?

Is there any way to manually install distutils in the Vercel environment, or should I use an alternative approach?

Are there known compatibility issues with certain packages when deploying Django on Vercel with Python 3.12?

Back to Top