0

I have Python-3.8.1 installed in my virtual environment, but still the default version is Python-2.7 only (because of MacOS)

Now, whenever I try to run a command starting with python3, such as python3 manage.py startapp ... or python3 manage.py runserver, I get this error:

SyntaxError: Generator expression must be parenthesized

enter image description here

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
  • What virtual environment are you using? – isAif May 19 '20 at 10:06
  • Please add the complete error in your question – isAif May 19 '20 at 10:07
  • Hi @HeisAif, I used "conda create --name myDjangoEnv django" to create my virtual environment – Prasun Gourav May 19 '20 at 15:24
  • Does this answer your question? [SyntaxError: Generator expression must be parenthezised / python manage.py migrate](https://stackoverflow.com/questions/48822571/syntaxerror-generator-expression-must-be-parenthezised-python-manage-py-migra) – isAif May 19 '20 at 15:48

2 Answers2

0

Are you using an older version of Django? Based on this Django 1.11 and Python 3.7+ are incompatible.

To upgrade your django package, first switch to your virtual environment:

conda activate your-django-env-name

Then run the following command to get the latest version on your virtual environment:

pip install django --upgrade

Winston
  • 601
  • 1
  • 9
  • 29
  • Hi @Winston, yes, my Django version is 1.11.29 and it is installed in the Python2 folder.....Now, how do I install the latest version of Django, like 3.x, in the Python3 folder?? – Prasun Gourav May 19 '20 at 15:29
  • First, switch to your venv using `conda activate myDjangoEnv`, then run `pip3 install django --upgrade` to get the latest version. – Winston May 19 '20 at 15:33
  • upgrading the django version may break the application itself, its better to use older version of python (version 3.6) which supports django being used. – isAif May 19 '20 at 15:46
  • Ok! It seems like he is just starting the project and creating apps in which case using the latest version is the better choice! – Winston May 19 '20 at 15:50
  • 1
    Agree, if using an already existing project or following a tutorial with a particular version of django, better use the required django, else using latest version of django is better option. – isAif May 19 '20 at 15:56
0
  1. To create an environment with a specific version of Python:

conda create -n myenv python=3.6

  1. To create an environment with a specific package:

conda create -n myenv django=1.11.29

For your use case I suggest:

conda create -n myDjangoEnv python=3.6 django=1.11.29

First activate the conda environment before running any commmand:

conda activate myDjangoEnv

You won't be required to type 'python3', simply use 'python'.

isAif
  • 2,126
  • 5
  • 22
  • 34
  • Since you already have an environment named 'myDjangoEnv', try making a new environment using method in answer and see If the error gets solved. – isAif May 19 '20 at 15:37