Skip to content

Installing Python

Before we start, it is important to install the necessary tools. This way, we can run the code to test see the result. This will also help us understand the behavior of Python. Follow the instructions below to set up your programming environment.

There are also some additional libraries we will be using.

  • PIL: Used to render images.
  • PILLOW: Modern replacement for PIL.

Windows

Important

You will need to be connected to the internet for ALL the installation steps as the required packages will need to be downloaded.

Step 1: Download Python

Head over to Python website. You should see something similar to the following. Choose Python 3.12.X where X is the latest patch version.

Download

Then choose Windows installer (x-bit) where x depends on your computer architecture. Usually this will be 64-bit but you need to check your computer.

Installer

This will initialize the download of the installer. Choose the directory to store the installer. Alternatively, choose the default directory which is the Downloads directory.

Step 2: Run Installer

Open the directory containing the installer. If you choose the default directory, it should be in the Downloads directory. Double-click on the installer to execute the installer.

Dialog

Important

Ensure that you check the box that says "Add python.exe to PATH" as seen in the red box above. This is important to ensure that Python is installed in your execution path.

Click on "Install Now" to install Python. This will complete in a few minutes. You should see a new program called IDLE in your programs menu once the installation is completed.

Step 3: Installing Packages

Open the Command Prompt from your Start Menu. You can click on Start Menu and start typing "command prompt".

Prompt

Enter the following command and press enter.

pip3 install pillow --no-cache-dir

Note

You may need to add python -m or py -m in front of the command above if it fails to run.

This will install the packages stated which is pillow. It will also install all other packages that are not stated but required by pillow. If successful, you should see a line saying "Successfully installed..." as seen below.

Pillow

Note

You may ignore the yellow text (if any). However, if you see a bunch of red text, the packages may not be installed properly.

Troubleshooting

Important

Use the following troubleshooting guide if you encounter problem during installation.

Checking if Python is Installed

Your Python path should be in the following form.

C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python312

Here, <USERNAME> is your username on your computer. This is how you can navigate to the directory.

  • Method 1: Windows Explorer

    • Go to Windows Explorer.
    • Click on the address bar.
    • Type the following.
      %localappdata%\Programs\Python\Python312
      
      Troubleshoot01
  • Method 2: Run

    • Press Win+R. This will open up Run.
    • Type the following.
      %localappdata%\Programs\Python\Python312
      
    • Click "OK".

      Troubleshoot02

pip Not Recognized

You may see the following error when running pip. Note that the color may not be red.

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

You may try running one of the following alternative command instead.

pip install pillow --no-cache-dir
pip3.12 install pillow --no-cache-dir
python -m pip3 install pillow --no-cache-dir
python -m pip3.12 install pillow --no-cache-dir

You can find more information here.

Checking if pip is Installed

To check if pip is installed, run one the following commands on Command Prompt.

py -m pip3 --version
python3 -m pip --version

Multiple Version

If you have multiple versions of Python, try running one of the following commands instead.

py3.12 -m pip3 --version
python3.12 -m pip --version

You should see an output similar to the one below.

C:\Users\USERNAME> py -m pip --version
pip 23.2.1 from C:\Users\USERNAME\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)

Adding Python to PATH Manually

Open settings and find "edit system" by using the search bar.

Troubleshoot03

Open "Edit the system environment variables" as seen above. You should see the following System Properties window.

Troubleshoot04

Click o "Environment Variables..." as circled in red above. You should see the window below.

Troubleshoot05

Select Path from the top list User variables for user. Then click Edit.... Add Python path by clicking New then key in the following two paths.

%localappdata%\Programs\Python\Python312
%localappdata%\Programs\Python\Python312\Scripts

To check if Python is already added to PATH variable, open Command Prompt and type the following.

echo %PATH%

This will gives you a list of directories added to the PATH variable. Ensure that the copied path is already there.

Checking if the Packages are Installed

Run the following command. As usual, you may need to add python -m (or other, similar as above).

pip freeze

The command checks all the Python packages insatlled. The result should be a list with the following format.

<package-name>==<package-version>

For example, you should see scipy==1.7.3 (or higher version), Check that the required packages are installed correctly. Alternatively, you can use pip list instead of pip freeze.

Upgrading pip

During installation of packages, you may receive a warning in yellow that pip must be upgraded. This is not necessary as long as you can work with the Python packages normally. However, should you need it, run the following command on Command Prompt.

pip --install upgrade pip

As usual, you may need to use python -m.

Subprocess Error When Installing Packages

As of now, this problem arises due to the incorrect Python installer chosen (e.g., using 32-bit installer on 64-bit machine or vice versa). As a result, you may see the following message.

Troubleshoot06

The solution is to simply switch the installer from 32-bit to 64-bit or vice versa. Uninstall the previous one to avoid any conflicts with the new installer. See the guide on Uninstallation to uninstall.

Issues with wheel During Installation

This might occur to some of you as the wheel package is not installed by default. Some issues that fall into this category include getting one of these messages when trying to install the packages.

  • "Could not build wheels for <package name> since package wheel is not installed"
    • This is an error and will stop the installation process before it finishes properly.
  • "Using legacy 'setup.py install' for <package name>, since package 'wheel' is not installed"
    • This is NOT an error but will very likely slow down the installation process.

The solution is to simply modify the installation command with the wheel package installed first. Run the following command.

pip3 install wheel pillow --no-cache-dir

Uninstalling Python

Note

This process is optional. However, one might easily confuse between different instances of Python that co-exist inside the computer. An example issue would be unable to import the packages on IDLE although the installation process ran smoothly, only to find out that the IDLE version does not match.

Open your settings and type "uninstall" on the search bar. Click on "Add or remove programs".

Troubleshoot07

Find the Python program that is to be uninstalled. The programs are arranged alphabetically. Click on "..." and click "Uninstall". For instance, the image below shows how to uninstall Python 3.11 since there are both Python 3.11 and Python 3.12.

Troubleshoot08

Reinstalling Python

Reinstalling Python may be needed if you have two or more instances of Python (e.g., Anaconda or Microsoft Store) and many errors appear during package installation due to certain clashes, which forces you to uninstall them. Here is what to do. Suppose you have to reinstall Python 3.12.1 again.

  • Reopen the installation file from Python website. This should be displayed the moment you open it. Note that you may also uninstall Python as seen in the last option below.

    Troubleshoot09

  • Click "Modify" and check everything. The last option is unchecked by default, so ensure that this is also checked.

    Troubleshoot10

  • Click "Next" and checked the the first three checkboxes that can be checked. Do not check the first checkbox. It is optional to check the last three options.

    Troubleshoot11

  • Click "Install".

Macintosh

Step 1: Download Python

Head over to Python website. You should see something similar to the following. Choose Python 3.12.X where X is the latest patch version.

Download

Then choose macOS 64-bit universal2 installer.

Installer

This will initialize the download of the installer. Choose the directory to store the installer. Alternatively, choose the default directory which is the Downloads directory.

Step 2: Run Installer

Open the directory containing the installer. If you choose the default directory, it should be in the Downloads directory. Run the installer.

Dialog

Click "Continue" to install.

Step 3: Installing Packages

Open the Terminal app. You can find the Terminal app by clicking on Finder on the dock and choosing: Utilities > Terminal.

Enter the following command and press enter.

pip3 install pillow --no-cache-dir

Note

You may need to add python -m or py -m in front of the command above if it fails to run.

This will install the packages stated which is pillow. It will also install all other packages that are not stated but required by pillow.

Note

You may ignore the yellow text (if any). However, if you see a bunch of red text, the packages may not be installed properly.

Troubleshooting

Important

Use the following troubleshooting guide if you encounter problem during installation.

Some Packages Cannot Compile Correctly

Attempting to run the installation command might sometimes result in compilation errors for M1 devices. Here are som epossible errors that fall under this category.

  • Incompatible Architecture

    Troubleshoot01

  • Python Quitting Unexpectedly

    Troubleshoot02

  • Subprocess Error While Installing Dependencies

    Troubleshoot03

If you encounter any of the problems above, follow the steps below for an alternative installation method.

Alternative Installation Method

  1. Install Homebrew by running the following command.

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

    If you receive a "Connection refused" error, consider switching your internet connection provider.

  2. You will be prompted to input your sudo password. This is your Mac password. It will NOT be shown when you are typing it, so make sure you are typing the correct password.

    ==> Checking for `sudo` access (which may request your password)...
    Password:
    
  3. Read and follow any additional instructions that you need to do on the terminal windows.

  4. Once finished, run the following command to install openblas and gfortran from Homebrew.

    brew install openblas gfortran
    
  5. Run the following command to uninstall your previously installed Python packages because we will be using a new one.

    pip3.12 freeze | xargs pip3.12 uninstall -y
    
  6. If you receive a prompt to upgrade your pip version, please do so by running the command shown on the screen.

  7. Quit the Terminal app.

    Important

    Quitting the Terminal app is different from merely closing the Terminal window. Make sure you do not have any Terminal windows open. Then you can use the command Cmd+Q. Alternatively, you can follow the image below.

    Troubleshoot05

  8. Locate Terminal in your Finder (User > Applications > Utilities). The image below will guide you as you navigate yourself through the files.

    Troubleshoot06

  9. Select Terminal and press Cmd+I OR right click and select "Get Info" as shown above.

  10. This will open the information window about Terminal. Check the "Open using Rosetta" option as seen in the image below.

    Troubleshoot07

  11. Reopen Terminal app.

  12. Run the following command.

    export OPENBLAS=/opt/homebrew/opt/openblas/lib/
    
  13. Run the following command.

    pip3.12 install pybind11 cython pythran pillow --no-cache-dir
    
  14. Locate Terminal in your Finder (User > Applications > Utilities). The image below will guide you as you navigate yourself through the files.

    Troubleshoot06

  15. Select Terminal and press Cmd+I OR right click and select "Get Info" as shown above.

  16. This will open the information window about Terminal. Uncheck the "Open using Rosetta" option as seen in the image below.

    Troubleshoot07

  17. Quit the IDLE application if it is still open.

  18. Locate IDLE in your Finder (User > Applications > Python3.12). The image below will guide you as you navigate yourself through the files.

    Troubleshoot08

  19. Select IDLE and press Cmd+I OR right click and select "Get Info" as shown above.

  20. This will open the information window about IDLE. Check the "Open using Rosetta" option as seen in the image below.

    Troubleshoot09

  21. Try and run the import statement again.

Packages Installed Correctly But Unable to Import

See below...

Previously Installed Anaconda/Conda

Sometimes due to multiple versions of Python installation present, IDLE will not import packages from the correct version. This issue is especially pertinent to users who have previously installed Anaconda.

If you are unsure about whether you have Anaconda installed, open a new Terminal window and look our for (base) on the left.

Troubleshoot10

Follow the guide linked to remove Anaconda.

Warning

Beware of the rm -rf command. Incorrect usage may result in PERMANENT and IRRECOVERABLE loss of data.

Additionally, open .zshrc or .bashrc and remove all traces of Anaconda. Check if the removal process is under control by closing ALL Terminal instances and reopening them.

However, if for any reason you want to keep Anaconda around, you do not have to remove them. Simply run deactivate to exit from the Anaconda base environment every time you launch Terminal. You can then follow the installation instructions again.

Bouncing Rocket Icon Appears in Dock

This is normal, you can ignore it.

This might happen when one tries to import cocos which will interact with the Python graphical user interface (GUI).