How to change “python manage.py” to “./manage.py”?

纵饮孤独 提交于 2021-02-10 09:33:42

问题


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:

  1. define the proper shebang [wiki] in the manage.py file; and
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!