Running .Py files in Windows

This blog is meant to act as a programming diary and solutions to the problems that I encountered while learning . I hope that this blogs provides help to my fellow programmers, too.

Currently trying to learn Python and improve my programming skills as well. I'm following Google Code Python classes for this purpose. While trying to run .Py files in Windows using Git Bash, I encountered the following error - sh.exe": python: no such command. To resole this problem, I did what I always do that is I googled it. And I found the following solution which I will now share with you all.

 As per the solution I found, courtesy of stackoverflow.com, this error means Git Bash does not know where your python.exe is. It searches your normal windows search path, the PATH environment variable. You're probably failing the 4th step on the instructions already "Make sure Python is working in the Git Bash":



$ python --version
sh.exe: python: command not found


To fix that, append C:\Python27 (or wherever you installed python) to your PATH environment variable in windows. You need to restart the bash after this for the change to take effect. This will allow you to run python from the windows command prompt as well.


And to set the path and environment variables in Windows 7, follow the following steps:


1. From the Desktop, right-click My Computer and click Properties.
2. Click Advanced System Settings link in the left column.
3. In the System Properties window click the Environment Variables button.



For those who don't want to alter your windows PATH variable or make python only available to git bash, you could create a .bashrc file in your %USERPROFILE% directory and set the variable there:

C:\>notepad %USERPROFILE%\.bashrc

and add

export PATH=/c/Python:$PATH

to the file. That script is executed every time you start the git bash and prepends C:\Python to git bash's PATH variable, leaving the system-wide PATH variable untouched.

Now that you know what has to be done, you can use this shortcut on the bash instead (appends the export command to your .bashrc)


$ echo export PATH=/c/Python:\$PATH >> ~/.bashrc
I have tried the changing the windows PATH solution and it works perfectly. Hope, this solutions helps you, too. 
Have a good day!!
MG


Comments

Post a Comment

Popular posts from this blog

Project Wild Penguin 12.4.2017: Installing Broadcom Wireless Drivers to connect to JBL Bluetooth Speaker on Xubuntu 16.10

Project Wild Penguin 22.4.2017: To delete directories inside current directory whose contents are less than a given size

ANPR Project Day 1: Standard Format of Indian Number Plate