'Invalid syntax with Django manage.py createsuperuser remote Terminal Mac
I'm trying to create a superuser on a remote django server. I am running a Mac.
On two separate terminals (not within VSCode or any IDE) I have run the following code using ssh and 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
On ssh, the python commands result in:
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
On ssh, the python3 commands result in:
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 <module>
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?
On sftp, both python and python3 commands result in Invalid command.
I have also tried:
Any other ideas? Thank you in advance!
Edit: It turned out there was an additional Docker container running on the server, which was why none of the above commands were working.
Solution 1:[1]
I made a new question to better reflect that this was an issue with Docker: How to create a python superuser within a remote docker container?
In the mean time, here is the code that did end up fixing the issue:
ssh <remote_address>
cd <application_dir>
cd src
docker ps # to determine that docker was present.
docker exec -it <container_id> ls src # to confirm manage.py is present
docker exec -it <container_id> sh
cd src
python manage.py createsuperuser
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Asa |
