There are times when you would like to have access to an executable file in your commandline. You need to add the directory to your PATH in environment variables.
In this article, we’ll look at how to add python to our PATH so as to be able to run python from command line.
Install Python. If you’ve done that, then you should have the folder Python2X or Python3X in your C: drive.
Now that we know where it is, let’s add the directory to our PATH so we can call python from the command line.
Inside Python27 is the python executable, that means the path C:/Python27/ is what we need in order to allow Windows access the executable from the command line. Copy that path.
To get to the environment variables (of which PATH is part), right click on “This PC” (same as “My Computer” for other Windows versions), click on properties.
Click on Advanced system settings under properties. Click on environment variables.
In the list of variables, if PATH already exists, edit it and add yours as a new path. In older versions of Windows, you add new paths to the PATH variable by separating them with semi-colons. (So path may have the value C:/Python27;C:/Python27/Sites;C:/somefolder/)
Now it’s done. Open command line, type python. If it throws no error, you’re done. You can add any directory containing executable files you want to access from command line the same way.