Skip to main content

Installing Python and xlwings (Legacy)

warning

This is an old article.
For installation, refer to Installing Python and xlwings.
This article is scheduled for deletion.

The reason: pyenv-win is no longer maintained.

What is xlwings?

  1. A library that allows Python to interact with Excel
    1. Official site: https://docs.xlwings.org/en/stable/index.html
tip

There are several ways to run Excel using Python, but as of 2025-02-10, I consulted ChatGPT and it recommended xlwings. So this guide follows that recommendation.

Before Installing Python

tip
  1. To avoid installing multiple Python versions, I used a version manager called 'pyenv-win'.
  1. If you previously installed Python via the Microsoft Store, uninstall it.
    1. If the version is acceptable (see here), you can keep it.

Installing pyenv-win

  1. Reference used: Installing and Running pyenv-win
    1. https://qiita.com/probabilityhill/items/9a22f395a1e93206c846
  2. Run the commands below with PowerShell 7 in Administrator mode
  3. My preferred installation method was using Git:
    1.  git clone https://github.com/pyenv-win/pyenv-win.git "$HOME/.pyenv"

Verifying pyenv-win Installation

tip

Display Environment Variables

  1. Press Windows + R to open "Run" and enter the following:
    1.  %WINDIR%\System32\SystemPropertiesComputerName.exe
    2. Click the "Advanced" tab > "Environment Variables..."
  1. Check that the following environment variables exist:
    1. PYENV
    2. PYENV_HOME
    3. PYENV_ROOT
  2. Make sure your Path environment variable includes:
    1. C:\Users\<user>\.pyenv\pyenv-win\bin
    2. C:\Users\<user>\.pyenv\pyenv-win\shims
  3. Check the pyenv version:
    1.  pyenv --version

Confirm the Python Version to Install

  1. First, check which version of Python is recommended for xlwings:
    1. https://docs.xlwings.org/en/stable/installation.html
  2.  pyenv install --list

Installing Python

  1. Install the Python version recommended for xlwings
    1. At the time of writing (2025-02-06), version 3.9 was recommended:
      1.  pyenv install 3.9.13
  2. Check the installed Python version:
    1.  python --version
  3. If the version doesn’t show up or something seems wrong, check the path being used:
    1.  gcm python | fl
    2. If the path is not .pyenv\pyenv-win\shims\python.bat, check your environment variables.
      1. If the path is C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\python.exe, it will take priority regardless of PATH, so delete python.exe and python3.exe in that folder.
        1. tip

          These files are just shortcuts to the Microsoft Store and can be safely deleted.

Installing xlwings

  1.  pip install xlwings
  2. Install the add-in:
    1.  xlwings addin install
    2. Once installed, the add-in will appear as a tab in Excel
      1. img
  3. Done!

If You Need Optional Dependencies for xlwings

  1. https://docs.xlwings.org/en/stable/installation.html#optional-dependencies

Updating xlwings

  1.  pip install --upgrade xlwings
  2. Reinstall the add-in after upgrading:
    1.  xlwings addin install