Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a program runnable from the commandline without typing its full path?

I can best explain my question with an example. I recently downloaded Python for Windows, installed to C:\Python. So if I'm in folder X that contains myscript.py, and I want to invoke it, I have to call this:

> C:\Python\python.exe myscript.py

But it would be super-cool if I could just do this, from within any folder:

> python myscript.py

How do I make that "global"?

like image 652
soapergem Avatar asked Jul 17 '09 19:07

soapergem


People also ask

How do I run a program directly from terminal?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How do I make a script executable from anywhere?

To make the program executable from anywhere for all users, we can add it to the global profile settings in /etc/profile. We should note that /etc/profile and ~/. bash_profile are specific to the Bash shell. Other shells will likely use different locations.


2 Answers

You just need to add the path C:\Python to your Path Environment Variable which can be modified from the Advanced tab of the System Properties control panel.

like image 104
Mark Biek Avatar answered Sep 19 '22 05:09

Mark Biek


To eliminate the need to type python before your script, you can do the following:

  1. Add python.exe to your system PATH environment variable, if it's not already there.
  2. Add ;.py to the end of your PATHEXT system environment variable.

Then, instead of typing

> C:\Python\python.exe myscript.py

or

> python myscript.py

you can just type

> myscript.py
like image 45
Patrick Cuff Avatar answered Sep 20 '22 05:09

Patrick Cuff