How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (2024)

Last Updated : 28 Jul, 2020

Improve

We all know that nowadays Python is one of the most popular coding languages among all. While installing Python, one IDE named IDLE is also installed. Using the IDLE we can write and also run our programs. But we can also run python programs on CMD or command prompt as CMD is the default command-line interpreter on Windows.

But there’s a need to set up the environment variable in windows to use python on the command-line. Following are the steps to add Python Environment to Windows path:

Step 1: For setting up Python on CMD we must check whether Python is installed on your machine or not. For doing this go to the Windows search bar and search for python. If you find python in the result then you are good to go.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (1)

You can see Python3 is installed on my computer

If python is not installed on your computer, then it can be installed with How to install Python on Windows?.

Step 2: Now check whether python is already set up in Command Prompt or not. For doing this just open cmd and type python. If you see any python version then it is already setup.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (2)

You can see after typing python nothing happened. So, python is not set up on cmd yet.

Step 3: Now open the Windows search bar and search for “idle”. Without opening the app click on “Open file location”. If you didn’t get the option right click on the app and you will get it.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (3)

Now a file location will be opened on Windows explorer.

Step 4: Now right-click on “IDLE” and click on “open file location”

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (4)

Click on “Open file location”

After opening the file location copy the path.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (5)

Copy the location

Step 5: Now go to the windows search bar and search for “Environment variables” and open it.

After opening the menu click on “Environment Variables”

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (7)

Click on the “Environment Variables”

Now double click on the “path” in the “System Variables”

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (8)

In the “Edit System Variable” menu click on “new”, then paste the file location you copied and click ok.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (9)

Now close the Environment menus by clicking ok and congratulation, we have set up the Command Prompt for python.

Step 6: Now check whether it works. Open Command Prompt and type “python” and hit enter. You will see a python version and now you can run your program there.

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (10)


Like Article

Suggest improvement

Share your thoughts in the comments

Please Login to comment...

How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks (2024)

FAQs

How do I setup a Python Command Prompt in Windows 10? ›

Go to Python's website and download the latest version of Python. Select “Windows installer” and click download. Follow the on-screen instructions. Verify the installation by opening a command prompt and typing: python -V .

How to run Python code from Command Prompt? ›

To run a Python script in Terminal from the command line, navigate to the script's directory and use the python script_name.py command. Redirecting output involves using the > symbol followed by a file name to capture the script's output in a file. For example, python script_name.py > output.

How to set Pythonpath in Windows 10 command line? ›

Set PYTHONPATH using Command Prompt

Click on "Edit the system environment variables". Click on the "Environment Variables" button. Under "System Variables", click on "New" to add a new environment variable. Enter PYTHONPATH for the variable name and c:\path\to\my\modules for the variable value.

How do I create a Command Prompt for Python in Windows? ›

Search for cmd on the toolbar, then hit Enter. Once the command prompt is open, simply type python and hit Enter again. When you're in an interactive session, every Python statement is executed immediately and any output is displayed directly beneath.

How to install Python Command Prompt? ›

Python Installation on Windows
  1. Step 1: Select Python Version. ...
  2. Step 2: Download Python Executable Installer. ...
  3. Step 3: Run Executable Installer. ...
  4. Step 4: Add Python to Path (Optional) ...
  5. Step 5: Verify Python Was Installed on Windows. ...
  6. Step 6: Verify PIP Was Installed. ...
  7. Step 7: Install virtualenv (Optional)
Dec 5, 2023

How to run Python script Windows 10? ›

Navigate to the Script's Directory: Use the cd command to navigate to the directory where your Python script is located. Run the Script: Enter python scriptname.py, where scriptname.py is the name of your Python script. This command will execute your script.

Which command will start the Python prompt on your computer? ›

The Python Command Prompt

This is the Python interpreter that we've been running in Wing and ArcGIS all along. Type "python" into the command line and you'll see the "Python Command Prompt" appear. Type "print("hello world")" and hit return. You should see "hello world" printed on the next line.

How to run code in command prompt? ›

How to run a file in command prompt
  1. Open command prompt. There are several ways to open the command prompt app. ...
  2. Open the file pathway. To open the correct file, direct the command prompt app to the correct file path in your Windows by using this command template: cd [file path]. ...
  3. Execute the file. ...
  4. Launch and use your file.
Jun 24, 2022

How to set Python path in PowerShell? ›

To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths . To set this variable from PowerShell, use: $env:PYTHONPATH='list;of;paths' just before you launch Python.

Where do I set Pythonpath? ›

If you are on Windows

From the advanced system settings dialog, choose the “Environment variables” button: In the Environment variables dialog, click the “New” button in the top half of the dialog, to make a new user variable: Give the variable name as PYTHONPATH and the value is the path to the code directory.

What is Python command in cmd? ›

In the command line, the command to run the Python hello.py program, the command is: $ python3 hello.py Hello World $ The first word "python3" means we want to run the Python interpreter which handles python programs, and then "hello.py" refers to the Python program we want to run.

How to run cmd command in Python with admin? ›

Using subprocess
  1. Command Prompt: command = ['cmd.exe', '/c', <argument>]
  2. PowerShell: command = ['powershell.exe', '-command', <argument>]
Mar 19, 2022

What is a Python command? ›

Command is behavioral design pattern that converts requests or simple operations into objects. The conversion allows deferred or remote execution of commands, storing command history, etc.

How to make Python script executable in cmd? ›

Here's a step-by-step guide on how to use PyInstaller to convert a Python script to an executable:
  1. Step 1: Install PyInstaller. ...
  2. Step 2: Navigate to your script's directory. ...
  3. Step 3: Run PyInstaller. ...
  4. Step 4: Locate the executable. ...
  5. Optional: Customize PyInstaller options. ...
  6. Note: ...
  7. Step 1: Install Auto PY to EXE.

Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 5639

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.