Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (amit_dhamankar):

What is the importance of "Path" the environment variable that we set before writing programs?

OpenStudy (woodrow73):

don't hold me to it, but I believe it enables you to run / compile programs from the cmd = command prompt. I personally just downloaded the jdk and eclipse, and didn't need to set the path variable

OpenStudy (anonymous):

I'll take Python for example, because it is first thing that comes to my mind when the Path variable is mentioned. Of course, we are talking about Widows OS here, and setting the path variable in Windows. Linux and Mac OS come with Python already installed. If you install Python, then write hello.py script, when you want to run it from command prompt, and you are currently in directory that hello.py script is in, you will have to type something like C:\python33\python hello.py in order to run the script. If you type just python hello.py, it will not run. But, if you go to Control Panel -> System -> Advanced System Settings, on Advanced tab click on Environment Variables... button, you'll get Environment variables dialog. Now, in System variables frame [lower frame of two], find Path variable and click on Edit... button. Add C:\python33\python at the end, delimited by semicolon. Note that your path may vary, depending on your installation path and Python version. Now, whatever directory is active, whatever folder you are in, it will be enough to type "python hello.py" and Windows will know where to find program "python" to execute it. Hope this helps.

OpenStudy (anonymous):

Just small edit to previous post: if you have your path variable set, and you are in directory other than the one that hello.py is in, you will have to type full path to the file. Windows will find python.exe, but will not find the script file, unless you type in the full path to the file.

OpenStudy (rsmith6559):

The PATH variable is used by the OS. It's prepended to program calls that don't have an absolute path. Something like the Python interpreter is installed from packages at /usr/bin/python. If you just type python into a shell, the OS realizes that the first character isn't a '/', so the OS prepends the first path in the PATH variable, and tries that. If that file exists, that program is launched. If not, the next path in the PATH variable is tried, and so on. If the program isn't found after exhausting the paths in the PATH variable, then the "file not found" message is given. Windows operates the same way, just different paths and messages.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!