I cannot get my Django app to deploy on the new Python platform.
chkur opened this issue ยท 11 comments
I cannot get my Django app to deploy on the new Python platform. Running the command python manage.py collectstatic --noinput
fails, both in the old config file style and in the new .platform/hooks/predeploy/collectstatic.sh
setup.
Either way Django is not being found as a Python package, as if the virtual environment has not beed activated. Do we now have to activate the virtual environment first?
Originally posted by @digicase in #15 (comment)
I wanted to migrate python app from Amazon Linux 1 to Amazon Linux 2 to remove some deploy workarounds. But now I need to write new workarounds for simple virtualenv activating. container_commands section is useless for python apps. At least - correct docs please, don't mislead people.
@chkur here's the code I have that works, in the file .platform/hooks/predeploy/collect_static.sh
The collect_static.sh
file needs the correct permissions, which is stated in the docs. The rest I had to work out myself and with the help of other commenters on issue #15
#!/bin/bash
source /var/app/venv/*/bin/activate
export PYTHONPATH=/var/app/staging
export DJANGO_SETTINGS_MODULE=config.settings.production
django-admin collectstatic --noinput --clear
@digicase thanks for reply.
I hope developers will fix python platform and/or docs. It looks like it's still beta state.
Thank you for the feedback. we are working on this issue.
I had a similar issue, not sure if it's related. When deploying with requirements.txt
, EB generates the Pipfile and all the python libraries end up in /var/app/venv/staging-LQM1lest
. However if I use a Pipfile myself, then gunicorn, pip, setuptools ends up in /var/app/venv/staging-LQM1lest
and everything else ends up in /var/app/venv/requirements-neJltVej
, which then gives the Django not found error.
We addressed this issue in the latest Python AL2 platform version - 64bit Amazon Linux 2 v3.1.0 running Python 3.7
We addressed this issue in the latest Python AL2 platform version - 64bit Amazon Linux 2 v3.1.0 running Python 3.7
What did you fix specifically? I am using v3.1.0 and still not able to run collectstatic:
This is how the documentation says to do it:
container_commands:
01_collectstatic:
command: "django-admin.py collectstatic --noinput"
but it fails with:
/bin/sh: django-admin.py: command not found
I have also tried
container_commands:
01_collectstatic:
command: "python manage.py collectstatic --noinput -c"
and that fails with:
File "manage.py", line 14 ) from exc ^
SyntaxError: invalid syntax
It's still not working always command not found. please update your docs to Linux 2 ASAP
Any update on this? The old platform is deprecated and I cannot migrate some projects because of this issue and lack of proper documentation
Having issues with the lack of documentation on this, still.
in .platform/hooks/postdeploy/10-collectstatic.sh
:
#!/usr/bin/env bash
cd /var/app/current
mkdir -p staticfiles
chown -R webapp:webapp staticfiles
$PYTHONPATH/python manage.py collectstatic