51

I'm really new in programming and I wanted to follow the Djangogirls tutorial, but I'm stucked now. In the tutorial, I am here:

To create a database for our blog, let's run the following in the console: python manage.py migrate (we need to be in the djangogirls directory that contains the manage.py file). If that goes well, you should see something like this: ...

There is no option to fail in the tutorial but I have an error message:

(myvenv) C:\Users\Julcsi\djangogirls> python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\core\management\__init__.py", 
line 364, in execute_from_command_line
utility.execute()
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\core\management\__init__.py", 
line 338, in execute
django.setup()
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\__init__.py", 
line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\apps\registry.py", 
line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\apps\config.py", 
line 94, in create
module = import_module(entry)
File "C:\Users\Julcsi\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", 
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 723, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_remove
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\__init__.py", 
line 4, in <module>
from django.contrib.admin.filters import (
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\filters.py", 
line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\options.py", 
line 12, in <module>
from django.contrib.admin import helpers, widgets
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\widgets.py", 
line 152
'%s=%s' % (k, v) for k, v in params.items(),
SyntaxError: Generator expression must be parenthesized

What am I doing wrong? What should I do?

I have Python 3.7.0b1

Thanks a lot in advance for the help :)

julo6
  • 511
  • 1
  • 4
  • 3

9 Answers9

75

You’re not doing anything wrong; this is a problem between Django and Python 3.7. Django has a fix, but that fix hasn’t made it into a new version yet.

You can install the stable version of Python, Python 3.6, in the meantime.

Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Thanks a lot for your answer!! :) I tried to uninstall 3.7 but in Command line, I still see the Python 3.7 as the version used... I don't understand why. I uninstalled Python 3.7. with the "python-3.7.0b1-amd64.exe" + Uninstall button. I cannot see it in my files. What have I done wrong? – julo6 Feb 17 '18 at 21:17
  • Ohh, sorry, now I realized that the problem occures only in the 'myvenv' virtual environment (after I type in the "myvenv\Scripts\activate") – julo6 Feb 17 '18 at 21:28
  • @julo6: Yeah, unfortunately the only sure way to deal with that is to delete the venv and make it again. (So if you already did that, it was the best option.) – Ry- Feb 18 '18 at 05:40
  • 1
    Thank you so much! No, I didn't realized that I should have delete the venv and make it again... So your comment saved me :D Now it works! Thanks again! – julo6 Feb 18 '18 at 23:27
  • 1
    As per https://github.com/django/django/commit/931c60c#commitcomment-30238549, this will never be fixed. Django 1.11 LTS and Python 3.7+ will be incompatible. – hyperknot Aug 31 '18 at 17:45
  • 1
    @hyperknot: The tutorial is kept up to date – installs 2.0.x now – so it’s fixed. – Ry- Aug 31 '18 at 20:56
  • Django itself is not fixed, that's the core of the problem. – hyperknot Sep 01 '18 at 14:41
16

This is a known incompatibility between Django and Python 3.7. A fix has already been merged into Django 2.x branches and backported into 1.11 branch.

To solve this issue, simply update Django to at least version 1.11.17 (or 2.x) or you can downgrade Python to version 3.6.

Antwane
  • 20,760
  • 7
  • 51
  • 84
13

Also, upgrading Django solved my problem

On your terminal,

$ pip install -U Django

or see here

Chiharu Miyoshi
  • 133
  • 1
  • 6
3

Only Django==2.2 will be supported to Python 3.7 so upgrading your Django Version will solve your problem

pip3 install django --upgrade
2

The Django Girls tutorial version in English has just switched to Django 2.0 which should make it compatible to Python 3.7. (Django 2.0 includes a backport of the fix mentioned in Ry-'s answer.)

So everyone beginning the tutorial now should be fine with Python 3.7.

If you've already begun the tutorial you'd have to start again at the Django installation chapter. You'll want to do that in a new directory (either delete or rename your current djangogirls directory or choose a different name for the new directory) as the files generated by

django-admin print startproject mysite .

depend on the Django version in use.

das-g
  • 9,718
  • 4
  • 38
  • 80
  • [Translations of the tutorial to other languages](https://tutorial.djangogirls.org/) might need some time to catch up with that change. If you'd like to help with that, see [here](https://tutorial.djangogirls.org/en/#would-you-like-to-help-us-translate-the-tutorial-into-other-languages). – das-g Jul 17 '18 at 13:42
1

Per Django's FAQ, Django 1.11.x is not compatible with Python 3.7.

Django 1.11.x reached end of mainstream support on December 2, 2017 and it receives only data loss and security fixes until its end of life.

Tim Graham
  • 1,495
  • 3
  • 16
  • 17
0

As all of the above answers already suggesting that there's a miss match between Django and Python version.
While creating a virtual environment, please run the following command

python3.6 -m venv myenv

It will use Python3.6 while creating your virtual environment.
Now you can install all the dependencies in this virtual environment.

Akash Giri
  • 141
  • 1
  • 7
0

I got this issue solved by upgrading Django to Dajngo==1.11.29, the last release of Dajngo 1.11. I think my python version was 3.8.x. Give it a try if you are not planning to upgrade to Django 2.x or 3.x

Mohammed Shareef C
  • 3,829
  • 25
  • 35
-1

Follow the below-mentioned steps to fix the issue:

  • Move to the directory where you have installed the virtualenv
  • You will find a directory named lib. Inside that directory, you will find a directory named pythonx.y where x.y is the version of python you are using
  • Now, go to site-packages
  • Then go to the directory django
  • Move to contrib directory
  • Now, go to admin directory. This is where you would find a python file widgets.py
  • Find the following code snippet in that file
            if params:
                related_url += '?' + '&amp;'.join(
                related_url += '?' + '&amp;'.join('%s=%s' % (k, v) for k, v in params.items())
                    '%s=%s' % (k, v) for k, v in params.items(),
                )

You need to change that to the following

            if params:
                related_url += '?' + '&amp;'.join(
                related_url += '?' + '&amp;'.join('%s=%s' % (k, v) for k, v in params.items())

Save the changes and execute the migrate again.

The_Vats
  • 199
  • 2
  • 9
  • Changing a 3rd party library's source code is not a good idea. better to upgrade to a version of Django that supports the python version – famagusta May 28 '21 at 06:31