0

How do I call a python program from the command line? Where the program should be?

What's the difference between the python GUI and the command line?

0

2 Answers 2

2
python yourscript.py

or you can prepend to your script the following:

#!/usr/bin/env python

and then run chmod +x yourscript.py in commandline. Good editors can do it automatically for you.

When you run a script from a GUI (like nautilus), it executes it because it has the execute flag on, and the shebang thing within, otherwise the GUI won't recognize it.

Finally, to "install" it as a CLI command, you have to put it in one of the directories of the $PATH environment variable (usually, /usr/local/bin, /usr/bin or /bin).

But a good way to make your script correctly installed, you'd better package it using a setup.py file, here's a tutorial: http://pythonhosted.org/an_example_pypi_project/setuptools.html‎. It will help you to put all your python scripts where it belongs, and create scripts in standard directories for you to run them as commands... You can even create menu items links for your window manager, so one can just double click to launch your app once installed!

Sign up to request clarification or add additional context in comments.

Comments

0
python yourscript.py

The GUI just facilitates execution.

2 Comments

where yourscript.py should be?
You'll need to go into a text editor and save the file as yourscript.py. From the command line, go to the directory where the file resides and type "python yourscript.py". Just typing "python" by itself should toss you into the interpreter environment where you can experiment interactively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.