Как решить SyntaxError на автоматически сгенерированном manage.py?
Я следую учебнику Django https://docs.djangoproject.com/es/1.10/intro/tutorial01/ Я создал «mysite» фиктивный проект (мой самый первый) и попытаюсь проверить его, не изменяя его.
django-admin startproject mysite cd mysite python manage.py runserver File "manage.py", line 14 ) from exc ^ SyntaxError: invalid syntax
Я получаю SyntaxError в файле, который был создан самой системой. И я, похоже, не могу найти кого-либо еще, кто прошел через ту же проблему. Я добавлю некоторые данные моей установки, если это может быть полезно
$ 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
Может кто-нибудь, пожалуйста, помогите мне? Обновление: добавление содержимого autogenerated manage.py
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 installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv)
Пожалуйста, опубликуйте содержимое всего файла (или, по крайней мере, больше) с синтаксической ошибкой.
Этот файл предназначен для использования с Python 3 (обратите внимание, что это первая строка!) И не будет работать в 2.7.
В учебном веб-сайте говорится, что, когда какая-то часть кода не будет работать с 2.7, они добавят необходимые изменения в комментарии. Это не было никаких изменений в списке, поэтому я предположил, что это будет работать .
Неверный синтаксис в Django manage.py createsuperuser remote Terminal Mac
Я пытаюсь создать суперпользователя на удаленном сервере django. Я использую Mac.
На двух отдельных терминалах ( не в VSCode или какой-либо IDE) я выполнил следующий код, используя ssh и sftp :
cd my_dir/src ls # to confirm manage.py is present python manage.py createsuperuser python3 manage.py createsuperuser sudo python manage.py createsuperuser sudo python3 manage.py createsuperuser
На ssh , команды python приводят к:
File "manage.py", line 16 ) from exc ^ SyntaxError: invalid syntax
На ssh , команды python3 приводят к:
Traceback (most recent call last): File "manage.py", line 10, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py", line 16, in main ) from exc 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?
При sftp обе команды python и python3 приводят к Invalid command.
Есть другие идеи? Заранее спасибо!
Я создал новый вопрос, чтобы лучше отразить, что это проблема с Docker: Как создать суперпользователя python в удаленном контейнере docker?
В то же время, вот код, который в итоге исправил проблему:
ssh cd cd src docker ps # to determine that docker was present. docker exec -it ls src # to confirm manage.py is present docker exec -it sh cd src python manage.py createsuperuser
Неверный синтаксис в Django manage.py createsuperuser remote Terminal Mac
Я пытаюсь создать суперпользователя на удаленном сервере django. Я использую Mac.
На двух отдельных терминалах ( не в VSCode или какой-либо IDE) я выполнил следующий код, используя ssh и sftp :
cd my_dir/src ls # to confirm manage.py is present python manage.py createsuperuser python3 manage.py createsuperuser sudo python manage.py createsuperuser sudo python3 manage.py createsuperuser
На ssh , команды python приводят к:
File "manage.py", line 16 ) from exc ^ SyntaxError: invalid syntax
На ssh , команды python3 приводят к:
Traceback (most recent call last): File "manage.py", line 10, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py", line 16, in main ) from exc 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?
При sftp обе команды python и python3 приводят к Invalid command.
Есть другие идеи? Заранее спасибо!
Я создал новый вопрос, чтобы лучше отразить, что это проблема с Docker: Как создать суперпользователя python в удаленном контейнере docker?
В то же время, вот код, который в итоге исправил проблему:
ssh cd cd src docker ps # to determine that docker was present. docker exec -it ls src # to confirm manage.py is present docker exec -it sh cd src python manage.py createsuperuser
Forums
I cannot get my django application to deply as my webapp. I have tried a few times over several days but I can’t get it to work.
I’m following the excellent DjangoGirls tutorial, specifically https://tutorial.djangogirls.org/en/deploy/.
I used my personal access token and was able to authenticate. However when I run the autoconfigure:
pa_autoconfigure_django.py --python=3.6 --nuke https://github.com/robline/skip.git
I get a collectstatic failed because there is no module named django_extensions:
ModuleNotFoundError: No module named 'django_extensions' Traceback (most recent call last): File "/home/robline/.local/bin/pa_autoconfigure_django.py", line 47, in module> main(arguments[''], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke')) File "/home/robline/.local/bin/pa_autoconfigure_django.py", line 37, in main project.run_collectstatic() File "/home/robline/.local/lib/python3.6/site-packages/pythonanywhere/django_project.py", line 87, in run_collectstatic '--noinput', File "/usr/lib/python3.6/subprocess.py", line 311, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/home/robline/.virtualenvs/robline.pythonanywhere.com/bin/python', '/home/robline/robline.pythonanywhere.com/manage.py', 'collectstatic', '--noinput']' returned non-zero exit status 1.
So I tried to install django-extensions and it says requirement already satisfied:
18:42 /home $ pip3.6 install --user django_extensions Looking in links: /usr/share/pip-wheels Requirement already satisfied: django_extensions in ./robline/.local/lib/python3.6/site-packages (3.0.9)
When I try to manually run collectstatic it fails because I’m not in the correct directory. I’d expect the automatic virtualenv creation to put me there which is why I mention it. Anyway I navigated to the correct directory to collect static, and also tried create superuser:
python manage.py collectstatic
18:50 ~/robline.pythonanywhere.com (main)$ python manage.py createsuperuser File "manage.py", line 17 ) from exc ^ SyntaxError: invalid syntax
I am not sure what else to try. Thanks for any insights!
The pa_autoconfigure_django.py script expects you to have a file in your repository called requirements.txt , which lists all of your site’s dependencies. It will then create a new virtualenv using the version of Python that you specified, and install those dependencies into it.
It looks like your repository either doesn’t have that file, or doesn’t list django_extensions in there, which is why you’re getting the first error. The result of that is that the virtualenv isn’t fully created, which is the cause of the other errors.
giles | 11514 posts | PythonAnywhere staff | Oct. 20, 2020, 10:10 a.m. | permalink
Thank you so much, that got me past the install.
I’m now having tons of pathing issues. It can’t find base.html for example. I’ve followed the steps at https://help.pythonanywhere.com/pages/DebuggingImportError and in a shell when I tried to import settings.py its said pathlib was missing. I installed pathlib and now it says ImportError: No module named py . Again I appreciate any light you can shed. I’m so close!
I wonder if you are running the wrong python in your shell. Make sure you are using your virtualenv python
conrad | 4232 posts | PythonAnywhere staff | Oct. 21, 2020, 10:40 a.m. | permalink
Ask us a question, or tell us what you love or hate about PythonAnywhere.
We’ll get back to you over email ASAP.
Forums
python: can’t open file ‘manage.py’: [Errno 2] No such file or directory
i was just following tutorial (http://tutorial.pythonanywhere.com/django) and then i got this error: python: can’t open file ‘manage.py’: [Errno 2] No such file or directory i sure have manage.py in its default folder, i didnt change anything with it, but it’s not working =( sorry for the dumb question, im a newbie here.
That can happen because manage.py does not have execute permissions. You can fix this with chmod +x manage.py .
glenn | 9197 posts | PythonAnywhere staff | July 15, 2013, 11:30 a.m. | permalink
thank u for help, i tried that, but still not working( 10:50 ~ $ python ./manage.py syncdb
python: can’t open file ‘./manage.py’: [Errno 2] No such file or directory
12:03 ~ $ chmod +x manage.py chmod: cannot access ‘manage.py’: No such file or directory
but i definetely have that file, here’s a screenshot: http://postimg.org/image/9gkaw9ob5/
my friend helped me. the answer is, if anyone will ever need it, is u gotta use this command:
python ./mysite/manage.py syncdb
Yes, it’s because the file was located in a subdirectory. You need to either enter the appropriate subdirectory (with cd ) or add it to the filename as you’ve done in your example. If you need to brush up on this sort of thing, there are any number of introductory pages out there like this one or this one.
to me its still giving me the error
Are you in the directory where your manage.py file is?
glenn | 9197 posts | PythonAnywhere staff | March 9, 2017, 1:15 p.m. | permalink
that’s right. just use cd mysite and go to the same directory as your manage.py.
that’s right. just use cd mysite and go to the same directory as your manage.py.
I wrote cd mysite but I still got an error «bash: cd: mysite: Not such of file or directory«
Do you have a mysite directory to cd into? Is your site in a differently named directory?
glenn | 9197 posts | PythonAnywhere staff | Nov. 16, 2018, 11:51 a.m. | permalink
19:31 ~/feedcoder.pythonanywhere.com (master)$ cd /manage.py
bash: cd: /manage.py: No such file or directory
19:32 ~/feedcoder.pythonanywhere.com (master)$ python manage.py createsuperuser
File «manage.py», line 16 ) from exc ^ SyntaxError: invalid syntax
The error in your first post is because you’re trying to cd into something that doesn’t exist. If you want to reference a file in the current directory, you should just use something like «manage.py». The syntax «/manage.py» means «go up to the very top of the directory tree, then find the file or directory there called «manage.py». Additionally, «cd» is how you navigate into directories, and «manage.py» is a file, not a directory.
The second error is because you’re using the wrong version of Python to try to run the code. It looks like your website is set up to use Python 3.5, so the command to run manage.py would be this:
python3.5 manage.py createsuperuser
giles | 11514 posts | PythonAnywhere staff | Aug. 12, 2019, 11:18 a.m. | permalink
I was running into the same problem. I opened manage.py and was met this nugget of wisdom . «Did you forget to acivate a virtual environment?»
That fixed it for me and left me felling a bit foolish.