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?
- A library that allows Python to interact with Excel
- 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
- To avoid installing multiple Python versions, I used a version manager called 'pyenv-win'.
- If you previously installed Python via the Microsoft Store, uninstall it.
- If the version is acceptable (see here), you can keep it.
Installing pyenv-win
- Reference used: Installing and Running pyenv-win
- Run the commands below with PowerShell 7 in Administrator mode
- My preferred installation method was using Git:
-
git clone https://github.com/pyenv-win/pyenv-win.git "$HOME/.pyenv"
-
Verifying pyenv-win Installation
tip
Display Environment Variables
- Press Windows + R to open "Run" and enter the following:
-
%WINDIR%\System32\SystemPropertiesComputerName.exe
- Click the "Advanced" tab > "Environment Variables..."
-
- Check that the following environment variables exist:
PYENV
PYENV_HOME
PYENV_ROOT
- Make sure your
Path
environment variable includes:C:\Users\<user>\.pyenv\pyenv-win\bin
C:\Users\<user>\.pyenv\pyenv-win\shims
- Check the pyenv version:
-
pyenv --version
-
Confirm the Python Version to Install
- First, check which version of Python is recommended for
xlwings
: -
pyenv install --list
Installing Python
- Install the Python version recommended for xlwings
- At the time of writing (2025-02-06), version 3.9 was recommended:
-
pyenv install 3.9.13
-
- At the time of writing (2025-02-06), version 3.9 was recommended:
- Check the installed Python version:
-
python --version
-
- If the version doesn’t show up or something seems wrong, check the path being used:
-
gcm python | fl
- If the path is not
.pyenv\pyenv-win\shims\python.bat
, check your environment variables.- If the path is
C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\python.exe
, it will take priority regardless of PATH, so deletepython.exe
andpython3.exe
in that folder.-
tip
These files are just shortcuts to the Microsoft Store and can be safely deleted.
-
- If the path is
-
Installing xlwings
-
pip install xlwings
- Install the add-in:
-
xlwings addin install
- Once installed, the add-in will appear as a tab in Excel
-
- Done!
If You Need Optional Dependencies for xlwings
Updating xlwings
-
pip install --upgrade xlwings
- Reinstall the add-in after upgrading:
-
xlwings addin install
-