Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference in using: python manage.py [something] or ./manage.py [something]

Tags:

python

django

I'm wondering if there any difference in using of following constructions? python manage.py [something] or ./manage.py [something]

Maybe there is preffered command for one statement like runserver and another for syncdb for example?

like image 392
micgeronimo Avatar asked Feb 11 '23 22:02

micgeronimo


2 Answers

When invoking Python script via:

./script.py 

.. it uses the Python interpreter defined in the script head. This should point to the Python interpreter defined in the environment, though sometimes (rarely) this might not be the case if the script author has not put in a proper head.

When invoking Python script via:

python script.py

... it uses Python interprefer from PATH environment variable, usually pointing to the currently activated virtualenv. This is what you get if you run which python command.

In most situations the Python interpreter should be the same.

You could also do:

/usr/bin/python script.py

... to force the usage of system-wide Python installation.

EDIT: Clarified the script head part.

like image 101
Mikko Ohtamaa Avatar answered Feb 14 '23 12:02

Mikko Ohtamaa


There's no huge difference, except 2 things :

  1. You have to give the execute right to your file manage.py (chmod +x manage.py)
  2. The file has to contain for example #!/usr/bin/python at the top.
like image 27
FunkySayu Avatar answered Feb 14 '23 10:02

FunkySayu