1

I have been using windows os for development. I have very little understanding of commands in linux. I'm trying to deploy a django application on AWS EC2 instance but got stuck while trying to migrate to the database. I ran the command: sudo python3 manage.py migrate but I keep getting the following error.

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 11, in main
    from django.core.management import execute_from_command_line
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 13, in <module>
    from django.apps import apps
  File "/usr/local/lib/python3.5/dist-packages/django/apps/__init__.py", line 1, in <module>
    from .config import AppConfig
  File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 7, in <module>
    from django.utils.deprecation import RemovedInDjango41Warning
  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 114
    launch_map: "Dict[asyncio.Task[object], threading.Thread]" = {}
              ^
SyntaxError: invalid syntax

During development on windows os, whenever I run python manage.py migrate on the same project everything works well. But When I clone it from github I'm not able to migrate using linux ubuntu command. Please how do I fix the problem?

C-Bizz
  • 624
  • 9
  • 25
  • 2
    It looks like you use Python-3.5, and likely you developed this with a different version of Python. – Willem Van Onsem Sep 05 '21 at 11:16
  • 2
    `asgiref` requires Python 3.6 or newer. When you run `sudo python3` you are *not* using the same Python installation; you can see from the traceback that Python 3.5 is being used. – Martijn Pieters Sep 05 '21 at 11:17

1 Answers1

2

asgiref requires Python 3.6 or newer, but your Ubuntu Linux installation has Python 3.5 installed. The project uses syntax that is not available in 3.5.

You want to verify what Python version your project needs (try running python3 -V), then install that version onto your Linux machine (in addition to the standard python3` package). You can do so with the deadsnakes PPA. E.g. to install Python 3.9:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.9 python3-pip

From there, use sudo python3.9 .... Remember that you’ll need to install the project requirements again. If you have been using a virtualenv, you’ll need to upgrade it:

$ python3.9 -m venv --upgrade [your venv path]

Django 3.x releases all work with Python 3.6 through to 3.9, but your project may have other dependencies that narrow that list.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • But I have Django installed and I activated venv – C-Bizz Sep 05 '21 at 11:41
  • 1
    @C-Bizz not in Python 3.9. How did you install your project on Windows? Is there a requirements.txt file? I’m assuming you have been using `pip install` to get your dependencies installed. – Martijn Pieters Sep 05 '21 at 11:46
  • 1
    @C-Bizz a virtualenv is also specific for the Python version, but you can upgrade the environment: https://stackoverflow.com/questions/10218946/upgrade-python-in-a-virtualenv – Martijn Pieters Sep 05 '21 at 11:48