How to solve SyntaxError on autogenerated manage.py?

前端 未结 30 2108
囚心锁ツ
囚心锁ツ 2020-11-28 08:24

I\'m following the Django tutorial https://docs.djangoproject.com/es/1.10/intro/tutorial01/

I\'ve created a \"mysite\" dummy project (my very first one) and try to

相关标签:
30条回答
  • 2020-11-28 08:52

    activate env by the Following Command

      source  pathetoYourEnv/bin/activate
    

    then run command

    python manage.py runserver
    
    0 讨论(0)
  • 2020-11-28 08:53

    Just activate your virtual environment.

    0 讨论(0)
  • 2020-11-28 08:55

    The solution is straightforward. the exception from manage.py is because when running the command with python, Django is unable to predict the exact python version, say you may have 3.6, 3.5, 3.8 and maybe just one of this versions pip module was used to install Django to resolve this either use:

    ./manage.py `enter code here`<command>
    

    or using the exact python version(x.x) stands:

    pythonx.x manage.py <command>
    

    else the use of virtual environments can come in handy because its relates any pip django module easily to python version

    • create env with pyenv or virtualenv
    • activate (e.g in virtualenv => virtualenv env)
    • run using python manage.py command
    0 讨论(0)
  • 2020-11-28 08:55

    Also, the tutorial recommends that a virtual environment is used (see Django documentation: https://docs.djangoproject.com/en/2.0/topics/install/#installing-official-release"). You can do this with pipenv --three. Once you've installed django with pipenv install django and activated your virtual environment with pipenv shell, python will refer to python3 when executing python manage.py runserver.

    Pipenv documentation: https://pipenv.kennethreitz.org/

    0 讨论(0)
  • 2020-11-28 08:55

    I had this issue (Mac) and followed the instructions on the below page to install and activate the virtual environment

    https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

    $ cd [ top-level-django-project-dir ]

    $ python3 -m pip install --user virtualenv

    $ python3 -m venv env

    $ source env/bin/activate

    Once I had installed and activated the virtual env I checked it

    $ which python

    Then I installed django into the virtual env

    $ pip install django

    And then I could run my app

    $ python3 manage.py runserver

    When I got to the next part of the tutorial

    $ python manage.py startapp polls

    I encountered another error:

         File "manage.py", line 16
    
       ) from exc
                ^
    
       SyntaxError: invalid syntax
    

    I removed

    from exc
    

    and it then created the polls directory

    0 讨论(0)
  • 2020-11-28 08:56

    The django-admin maybe the wrong file.I met the same problem which I did not found on a different computer the same set-up flow.

    After comparing two project, I found several difference at manage.py and settings.py, then I realized I created 2.0 django project but run it with python2.

    runwhich django-adminin iterm

    /Library/Frameworks/Python.framework/Versions/3.6/bin/django-admin
    

    It looks like I got a django-admin in python3 which I didn't know why.So I tried to get the correct django-amin.

    pip show django
    

    then I got

    Name: Django
    Version: 1.11a1
    Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
    Home-page: https://www.djangoproject.com/
    Author: Django Software Foundation
    Author-email: foundation@djangoproject.com
    License: BSD
    Location: /Library/Python/2.7/site-packages
    Requires: pytz
    

    In/Library/Python/2.7/site-packages, I found the django-admin

    /Library/Python/2.7/site-packages/django/bin/django-admin.py
    

    So I created project again by

    /Library/Python/2.7/site-packages/django/bin/django-admin.py startproject myproject
    

    then run

    cd myproject
    python manage.py runserver
    

    succeeded

    0 讨论(0)
提交回复
热议问题