It has been very difficult for me trying to deploy to aws EC2 ubuntu server SINCE I'm coming from windows background. I encounter an error while trying to bind django application to gunicorn. The command I'm running is sudo gunicorn --bind 0.0.0.0:8000 logistics.wsgi:application
And the error log is show below:
(venv) ubuntu@ip-172-31-18-196:/var/www/html$ sudo gunicorn --bind 0.0.0.0:8000 logistics.wsgi:application[2021-09-08 11:21:00 +0000] [29379] [INFO] Starting gunicorn 20.1.0[2021-09-08 11:21:00 +0000] [29379] [INFO] Listening at: http://0.0.0.0:8000 (29379)[2021-09-08 11:21:00 +0000] [29379] [INFO] Using worker: sync[2021-09-08 11:21:00 +0000] [29382] [INFO] Booting worker with pid: 29382[2021-09-08 11:21:00 +0000] [29382] [ERROR] Exception in worker processTraceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/gunicorn/arbiter.py", line 589, in spawn_worker worker.init_process() File "/usr/local/lib/python3.5/dist-packages/gunicorn/workers/base.py", line 134, in init_process self.load_wsgi() File "/usr/local/lib/python3.5/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.5/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.5/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load return self.load_wsgiapp() File "/usr/local/lib/python3.5/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.5/dist-packages/gunicorn/util.py", line 359, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 665, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/var/www/html/logistics/wsgi.py", line 12, in <module> from django.core.wsgi import get_wsgi_application File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 2, in <module> from django.core.handlers.wsgi import WSGIHandler File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/wsgi.py", line 3, in <module> from django.conf import settings File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 19, in <module> from django.utils.deprecation import RemovedInDjango40Warning File "/usr/local/lib/python3.5/dist-packages/django/utils/deprecation.py", line 5, in <module> from asgiref.sync import sync_to_async File "/usr/local/lib/python3.5/dist-packages/asgiref/sync.py", line 115 launch_map: "Dict[asyncio.Task[object], threading.Thread]" = {} ^SyntaxError: invalid syntax[2021-09-08 11:21:00 +0000] [29382] [INFO] Worker exiting (pid: 29382)[2021-09-08 11:21:00 +0000] [29379] [INFO] Shutting down: Master[2021-09-08 11:21:00 +0000] [29379] [INFO] Reason: Worker failed to boot.
When I run gunicorn --bind 0.0.0.0:8000 logistics.wsgi:application
, (that is, without sudo
) I get another error:
(venv) ubuntu@ip-172-31-18-196:/var/www/html$ gunicorn --bind 0.0.0.0:8000 logistics.wsgi:applicationTraceback (most recent call last): File "/home/ubuntu/.local/bin/gunicorn", line 7, in <module> from gunicorn.app.wsgiapp import runModuleNotFoundError: No module named 'gunicorn'
But I have already install gunicorn with the command pip3 install gunicorn --user
. The reason why I added --user
at the end is that running pip3 install gunicorn
within the activated virtual enviroment is throwing back permission error as shown below:
(venv) ubuntu@ip-172-31-18-196:/var/www/html$ pip3 install gunicornCollecting gunicorn Using cached https://files.pythonhosted.org/packages/e4/dd/5b190393e6066286773a67dfcc2f9492058e9b57c4867a95f1ba5caf0a83/gunicorn-20.1.0-py3-none-any.whlRequirement already satisfied: setuptools>=3.0 in ./venv/lib/python3.6/site-packages (from gunicorn) (40.6.2)Installing collected packages: gunicornCould not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/www/html/venv/lib/python3.6/site-packages/gunicorn-20.1.0.dist-info'Consider using the `--user` option or check the permissions.You are using pip version 18.1, however version 21.2.4 is available.You should consider upgrading via the 'pip install --upgrade pip' command.
Again, I have already upgraded from python3.5
to python3.6
such that when I run python3 on the terminal I get the following output
(venv) ubuntu@ip-172-31-18-196:/var/www/html$ python3 --versionPython 3.6.13
Yet, I don't know why the error log is making reference to python3.5 instead of python3.6 as shown here: File "/usr/local/lib/python3.5/dist-packages/gunicorn/app/wsgiapp.py"
whenever I run sudo gunicorn --bind 0.0.0.0:8000 logistics.wsgi:application
Please I want to know why I'm getting that error