问题
I want to shorten python manage.py
to ./manage.py
.
This may be simple, but I couldn't find an answer for this. I saw a step by step method in one of the answers for questions about django but I did not memorize that. Tried to search for answers on stackoverflow to no avail.
Any help would be appreciated.
回答1:
If you're on a Unix based system:
Make sure the file has the proper shebang (=this line) as the topmost line (it should have this by default already):
#!/usr/bin/env python
Make your script executable by running:
$ chmod u+x manage.py
After that you're good to go.
回答2:
In order to do that, you will need to do two things:
- define the proper shebang [wiki] in the
manage.py
file; and - make the file executable.
Normally the manage.py
file already has a shebang at the top:
#!/usr/bin/env python
but depending on your system this might invoke python-2.x instead of python-3.x, you thus might want to change this to:
#!/usr/bin/env python3
If you make use of a virtual environment, you should let this point to the python executable of the virtual environment instead, so:
#!path/to/env/bin/python3
Next you make the file executable, you can do this with chmod
:
chmod +x manage.py
or if you only want to make it executable by the owner of the manage.py
file, you can use:
chmod u+x manage.py
来源:https://stackoverflow.com/questions/65438996/how-to-change-python-manage-py-to-manage-py