Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Python Command Prompt Setup: How to Install and Configure

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To get Python to work in the command prompt, you must install the Python interpreter and ensure the "Add Python to PATH" option is selected during installation. If Python is already installed but not recognized, you must manually add the Python installation directory and the Scripts folder to your system's environment variables. This process allows the Windows Command Prompt (cmd.exe) to recognize the python command from any directory rather than requiring you to navigate to the specific folder where the executable is stored.

What You'll Need

  • A computer running Windows 10 or Windows 11.
  • An active internet connection to download the installer.
  • Administrator privileges on the computer to modify system environment variables.
  • The official Python installer from python.org.

Step-by-Step

  1. Download the Installer: Open your web browser and navigate to the official Python website (python.org). Go to the Downloads section and select the latest stable version of Python for Windows. This will download an .exe installer file to your computer.
  2. Run the Installer: Locate the downloaded .exe file in your Downloads folder and double-click it to launch the installation wizard.
  3. Configure PATH (Critical Step): At the bottom of the first installation window, you will see a checkbox labeled "Add Python 3.x to PATH" (the 'x' represents the version number). Check this box. This is the most important step; if skipped, the command prompt will not recognize the python command, and you will receive a "'python' is not recognized as an internal or external command" error.
  4. Select Installation Type: Click "Install Now" for the standard installation. This will install Python in your local AppData folder and include the standard library and the pip package manager. If you prefer a custom location (such as C:\Python312), select "Customize installation," ensure "pip" is checked, and then proceed to the Advanced Options page to check "Install for all users" and set your custom path.
  5. Complete Installation: Wait for the progress bar to finish. Once complete, you may see an option to "Disable path length limit." It is recommended to click this to prevent potential issues with long file paths in deep directory structures.
  6. Open Command Prompt: Press the Windows Key, type cmd, and press Enter. This opens the Windows Command Prompt interface.
  7. Verify the Installation: In the command prompt window, type python --version and press Enter. If configured correctly, the prompt will return the version number (e.g., Python 3.12.1). You can also try typing py --version, as the Python Launcher for Windows often works even if the main PATH variable is slightly misconfigured.
  8. Test the Interactive Shell: Type python and press Enter. The prompt should change to >>>, indicating you are now inside the Python interactive shell. You can test it by typing print("Hello World") and pressing Enter. To exit this mode and return to the standard command prompt, type exit() or press Ctrl+Z and then Enter.

Common Mistakes

The most frequent error is forgetting to check the "Add Python to PATH" box during the initial installation. Many users assume that installing the software is enough, but Windows requires a specific pointer (the PATH variable) to know where the python.exe file resides. Without this, the command prompt searches its default directories and finds nothing, resulting in a command-not-found error.

Another common mistake is attempting to run Python commands in the command prompt while still inside the Python interactive shell. Once you see the >>> symbols, you are writing Python code, not Windows commands. If you try to run a command like pip install requests while inside the interactive shell, Python will throw a SyntaxError because pip is a standalone program, not a Python function. You must exit the shell first using exit() before running pip commands.

Some users accidentally install Python from the Microsoft Store instead of the official website. While the Store version works, it can sometimes create permission issues with certain libraries or create "app execution aliases" that conflict with manual installations. If you have both the Store version and the official version installed, the command prompt may default to the one listed higher in the environment variables, leading to confusion over which version is actually being used.

Tips

To make your workflow more efficient, use the Python Launcher. Instead of typing python, you can type py. The launcher is designed to handle multiple versions of Python installed on the same machine. For example, if you have both Python 3.9 and 3.12 installed, py -3.9 will launch the older version, while py -3.12 will launch the newer one.

When installing third-party libraries, always ensure your pip is up to date. You can do this by running python -m pip install --upgrade pip in the command prompt. Using the python -m prefix is safer than running pip directly because it ensures you are upgrading the pip associated with the specific version of Python currently active in your path.

Consider using Virtual Environments (venv) for your projects. Instead of installing every library globally, which can lead to version conflicts between different projects, you can create a local environment by typing python -m venv myenv. You then activate it using myenv\Scripts\activate. This keeps your global Python installation clean and ensures your project dependencies are isolated.

Troubleshooting

If you have already installed Python but the command prompt says 'python' is not recognized, you do not need to reinstall. You can manually add Python to your system PATH. First, find where Python is installed. Typically, it is in C:\Users\YourUsername\AppData\Local\Programs\Python\Python3x. Copy this path.

Next, search for "Edit the system environment variables" in the Windows Start menu and open it. In the System Properties window, click the "Environment Variables" button. In the "System variables" section, find the variable named Path, select it, and click "Edit." Click "New" and paste the path to the Python folder. Click "New" again and paste the path to the Scripts folder (which is inside the main Python folder). Click OK on all windows to save the changes. Crucially, you must close and restart any open Command Prompt windows for these changes to take effect.

If you type python and it opens the Microsoft Store page instead of launching Python, this is due to Windows "App Execution Aliases." To fix this, go to Settings > Apps > Apps & Features (or Advanced app settings) > App execution aliases. Find the entries for python.exe and python3.exe and toggle them to "Off." This prevents Windows from intercepting the command and redirecting you to the store, allowing it to use the version you installed manually.

If you encounter a "Permission Denied" error when trying to install packages via pip, try running the Command Prompt as an Administrator. Right-click the Command Prompt icon in the Start menu and select "Run as administrator." This gives pip the necessary permissions to write files into the Program Files or AppData directories.

Frequently Asked Questions

Do I need to restart my computer after adding Python to PATH?

No, a full computer restart is usually not necessary. However, you must close and reopen the Command Prompt window. The command prompt loads the environment variables only when it starts; it cannot detect changes made to the PATH while it is already running.

What is the difference between python and python3 commands?

On Windows, python is the standard command. On macOS and Linux, python often refers to the obsolete Python 2, while python3 refers to the modern version. If you are on Windows and python doesn't work but python3 does, it simply depends on how the executable was named during installation.

How do I know if pip was installed with Python?

You can check by typing pip --version in the command prompt. If it returns a version number and a file path, pip is installed. If not, you can install it by running the Python installer again, choosing "Modify," and ensuring the "pip" checkbox is selected.

Can I run Python scripts without entering the interactive shell?

Yes. Instead of typing python to enter the shell, navigate to the folder containing your script (e.g., cd Documents\Scripts) and type python script_name.py. This will execute the entire file from start to finish and return you to the command prompt.

Why does my command prompt say 'python' is not recognized even after I checked the PATH box?

This usually happens if the Command Prompt was open during the installation. The current session does not know about the new PATH variable. Close the window and open a fresh one. If that fails, verify that the installation actually completed without errors.

Is it better to use Command Prompt or PowerShell for Python?

For basic Python execution, both work similarly. However, PowerShell is more powerful for scripting and file management. Python commands like python and pip function identically in both environments, provided the PATH is configured correctly.