[email protected] +91-120-6025102
Submit

Avail Best discounts

Please fill in the form below and we will contact you within 24 hours.

How to Run Python in CMD?

Let's get into it pretty quick - you tried running ls command in your Python shell but noticed the same did not work. The problem you are likely to encounter is "ls is not defined" or "invalid syntax".

Note- ls command list

Cause- In the first place, you are facing this problem because ls is the command for Mac terminal and not Python shell.

It is very likely you have misunderstood the command use-case. The same is meant to work not in Python Shell but Command Prompt or Terminal (as you call it in Mac).


Try running the same in Terminal or Command Prompt. Below is the screenshot of the same.


cd desktop is Windows command to change active directory to desktop. dir is the ls equivalent in command prompt.


Type python in command prompt or Terminal in Mac and the result should look something like-


If typing “Python” leads to error, it is quite likely that you have not configured it with CMD. 

Here’s how to do it-

Right click on Computer and go to Properties.


Now click on advance system settings and then Environment Variables.


Click on environment variables, then scroll to the field where it says path. If it does not point to Python, edit path.

From My Computer, located the Python folder. Mine is located right inside the C drive.


From the address bar, copy the address and paste it in the path tab.

Overall, path field should finally look like-


Exit any running command terminals and try running it again – also, always run as an admin. 
Type in python.

This should load a few stats for your python.


Note, you can assign environment variables the same way even on your python hosting VM, provided you have Windows Server installed to it.

Was this answer helpful? #1 #0
 

Related Questions

Submit Query

Please fill in the form below and we will contact you within 24 hours.