Installing Python on Windows

Download PDF

1. Installing Python

Installing Python on your computer allows you to run Python code. Python is an interpreted high-level programming language with simple syntax.

You can install Python on Windows by following these steps:

  1. Go to the following link to download the installer: Python Download for Windows
  2. Click the latest Python 3 release.
  3. Scroll down to the files section at the bottom.
  4. Click Windows x86-64 executable installer and save the file (for 64-bit). If you need the 32-bit version, click Windows x86 executable installer.
  5. Once downloaded, run the installer.
  6. Important: Check the box that says Add Python 3.X to PATH. This makes it easier to install Python packages.
  7. Click Install Now.
  8. If prompted, allow the app to make changes to your device by clicking Yes.
  9. Wait until you see the "Setup was successful" screen, then click Close.

You have successfully installed Python on your computer. To open IDLE, search for "IDLE" in the Windows search bar.

2. Changing IDLE's Default Behavior

By default, IDLE opens in the Shell window, which allows you to run Python commands interactively, but does not provide an interface for writing longer scripts efficiently.

What is the IDLE Shell Window?

When IDLE is launched, it usually opens in the Shell window by default. The Shell window allows you to type and execute Python commands interactively. However, it is not ideal for writing longer scripts, as it does not allow saving or editing multiple lines of code easily.

How to Open the Edit Window by Default

To make IDLE open in the Edit window each time, follow these steps:

  1. Open IDLE.
  2. Go to the menu bar and click IDLE (on the top-left of the screen).
  3. Select Preferences... (under IDLE on MacOS).
  4. In the Windows tab, look for the option Open Edit Window under the "At Startup" section.
  5. Check the box next to it.
  6. Click Apply and OK to save your changes.

Now, every time you launch IDLE, it will open in the Edit window where you can write and save scripts easily.

If you prefer opening the Edit window manually, you can do so by:

This will allow you to start writing and saving Python scripts with ease.

3. Installing Command Line Tools

Command Line Tools, such as Git and Developer Tools, are essential for running Python in Visual Studio Code and other environments.

Installation Steps:

  1. Download and install Git for Windows. This provides essential command-line tools.
  2. During installation, select Use Git from the command line and also from 3rd-party software.
  3. Once installed, open Command Prompt and check if Git is installed by running:
git --version

If a version number is displayed, the installation was successful.

3. Installing Python Packages

Installing packages allows you to use code written by others. You can install them by following these steps:

  1. Search for cmd or Command Prompt in the Windows search bar and open it.
  2. Install Python packages using the following command:
pip3 install [insert package name(s) here], without the square brackets

For example, to install all the packages needed for CSCI 127 at Hunter College, type:

pip3 install numpy image matplotlib scipy pandas folium

You have successfully installed Python packages.

4. Troubleshooting

If you see the error:

'pip3' is not recognized as an internal or external command, operable program or batch file.

It means Python was not added to PATH during installation. To fix this:

Option 1: Reinstall Python

  1. Reinstall Python and ensure you check "Add Python to PATH" during installation.
  2. Follow the installation steps mentioned earlier in this guide.

Option 2: Manually Add Python to PATH

You can manually add Python to the system environment variables by following these steps:

  1. Open the Windows search bar and search for "Environment Variables".
  2. Click on "Edit the system environment variables".
  3. In the System Properties window, click on "Environment Variables...".
  4. Under the System variables section, scroll down and find the "Path" variable, then click "Edit...".
  5. Click "New" and add the path to your Python installation. By default, it should be:
C:\Users\YourUsername\AppData\Local\Programs\Python\Python3X

(Replace YourUsername with your actual Windows username and Python3X with your installed Python version.)

  1. Click "OK" to close all windows.
  2. Restart your computer to apply the changes.

Verifying the PATH Setup

Once you have manually added Python to PATH, verify the installation:

  1. Open the Command Prompt by searching "cmd" in the Windows search bar.
  2. Type the following command and press Enter:
python --version

If Python was successfully added to PATH, you should see the installed version displayed.

If you continue experiencing issues, consider reinstalling Python and following the installation steps carefully.

5. Installing and Setting Up Visual Studio Code for Python

Visual Studio Code (VS Code) is a popular code editor with features that enhance Python development. Follow these steps to install and set it up:

Installation Steps:

  1. Go to the official VS Code download page: Download VS Code.
  2. Click the Download for Windows button.
  3. Once downloaded, open the installer and follow the prompts.
  4. Check the box to add VS Code to the system PATH during installation.
  5. Launch VS Code from the Start menu.

Setting Up Python in VS Code:

  1. Open VS Code.
  2. Go to the Extensions tab on the left sidebar (or press Ctrl + Shift + X).
  3. Search for "Python" and install the extension provided by Microsoft.
  4. Once installed, open a new terminal inside VS Code (View > Terminal).
  5. Type
    python --version
    to check if Python is recognized.
  6. Create a new Python file (File > New File > Save as example.py).
  7. Write and run a test script:
print("Hello, Python in VS Code!")

Click the "Run" button (located in the tool bar near the top right of the VSCode window)

OR

Use Cmd + Shift + B to execute the script.

You have successfully set up Python in Visual Studio Code!

Author: Georgina Woo