Autachenated managed.py da SyntaxErrorni qanday echish kerak?

Django darsini tomosha qilaman https://docs.djangoproject.com/es/1.10/intro/tutorial01/

Men "mysite" qo'g'irchoq loyihasini yaratdim (birinchi mening) va uni o'zgartirmagan holda uni sinab ko'rishga harakat qilaman.

django-admin startproject mysite
cd mysite
python manage.py runserver

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

Tizimning o'zi tomonidan yaratilgan faylda SyntaxError-ni olaman. Men shu masalada o'tgan boshqa hech kimni topolmayapman.

Men sizning sozlamalaringizdan foydalanishingiz mumkin bo'lsa, ba'zi ma'lumotlarni qo'shib qo'yaman

$ vpython --version
Python 2.7.12
$ pip --version
pip 9.0.1 from /home/frank/.local/lib/python2.7/site-packages (python 2.7)
$ python -m django --version
1.10.6

Kimdir menga yordam berishi mumkinmi?

Yangilanish: Autogenerated managed.py tarkibini qo'shish

cat manage.py 
#!/usr/bin/env python3
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)
18
Ushbu fayl Python 3 (birinchi satrga e'tibor bering!) Bilan ishlashga mo'ljallangan va 2.7 da ishlamaydi.
qo'shib qo'ydi muallif jasonharper, manba
Iltimos, barcha faylning tarkibini (yoki hech bo'lmaganda undan ko'pi) sintaksik xato mavjud.
qo'shib qo'ydi muallif Scovetta, manba
O'quv qo'llanmasida aytilganidek, agar kodning ba'zi qismi 2,7 bilan ishlamasa, sharhlar uchun zarur bo'lgan o'zgartirishlarni qo'shib qo'yadi. Bu ro'yxatda hech qanday o'zgarish yo'q edi, shuning uchun men buni amalga oshirishni taxmin qildim ...
qo'shib qo'ydi muallif Frank, manba

8 javoblar

Djangoni qaysi python versiyasiga ulashingizga ishonch hosil qiling.

Django-ni o'rnatganingizda django-ni o'rnatib, python-dan foydalanishingiz mumkin. Agar siz pip3-ni ishlatgan bo'lsangiz, startapp-python-ni ishlatishingiz kerak. Terminal misolini ko'rish uchun bu yerni bosing django-ni o'rnatish, keyin python3 boshqarish.py startapp-ni ishlatishingiz kerak

29
qo'shib qo'ydi

python3 manage.py runserver bilan ishlashingiz mumkin. Bu men uchun ishlaydi.

9
qo'shib qo'ydi

you should activate your virtual environment . In terminal -> source env/bin/activate now there will be ----> (env) in your terminal displayed !

now it will work -> runserver .

Aks qismini o'chirishga hojat yo'q!

4
qo'shib qo'ydi

Faqat exec qismidan o'chirib tashlang, endi bunga o'xshash narsa bor

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        )
    execute_from_command_line(sys.argv)
3
qo'shib qo'ydi

Uning oddiy echimi aslida biriga kirib qoldi. Virtual muhitni yoqdingizmi?

mening terminal ekran rasmim

3
qo'shib qo'ydi

Haqiqiy ko'rsatmalarni (python2 yoki python3 ni faqat "python" o'rniga ishlatish bilan) sinovdan o'tkazganingizdan so'ng men o'qituvchining nima deyishidan qat'i nazar, bu faqatgina python3 bilan ishlayotganini tasdiqladim.

1
qo'shib qo'ydi

Bundan tashqari, darslik virtual muhitni ishlatishni taklif qiladi (Django hujjatlarini qarang: https://docs.djangoproject.com/en/2.0/topics/install/#installing-official-release " deb nomlanadi.) Buni pipenv --three pipenv install django bilan django'yu o'rnatganingizdan so'ng pipenv shell bilan virtual muhitingizni ishga tushirganingizda, python python manage.py runserver .

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

1
qo'shib qo'ydi

Django konteynerga o'rnatilgan bo'lsa-da, bu buyruqni ishlatayotgan kompyuterda bo'lmasligi mumkin. Keyin buyruq qanday ishlaydi? Shu sababli yuqorida hech qanday echim topilmadi.

I found out the running container and get into the running container using docker exec -it bash then ran the command inside docker container. As we have the volumed container the changes done will also reflect locally. What ever command is to be run can be run inside the running container

0
qo'shib qo'ydi
Python
Python
372 ishtirokchilar

Bu guruh python dasturlash tilini muhokama qilish uchun. Iltimos, o'zingizni hurmat qiling va faqat dasturlash bo'yicha yozing. Botlar mavzusini @botlarhaqida guruhida muhokama qling! FAQ: @PyFAQ Offtopic: @python_uz_offtopic

Python offtopic group !
Python offtopic group !
150 ishtirokchilar

@python_uz gruppasining offtop gruppasi. offtop bo'lsa ham reklama mumkin emas ) Boshqa dasturlash tiliga oid gruppalar @languages_programming