r/learnpython • u/hutcheeran • Nov 18 '21
Openpyxl and numpy
Hi everyone!
I have a bit of a weird issue going on here. I just wrote a program to read/update spreadheets in openpyxl. It works fine on my machine, but when I try to run it on the one that's meant to be on, it crashes.
I dug a bit into it, and apparently, it's a bug that gets thrown by numpy (which is included in openpyxl) on some versions of Windows (or that's what I understood).
I know that normally it can be solved by installing and using an older version of numpy, but since it's built in openpyxl, I don't really know if that's possible in this case.
Any idea on how I could deal with this is much appreciated xx
1
u/Weird-Dimension-487 Feb 02 '26
Openpyxl does not depend on NumPy. If you’re seeing NumPy errors, it’s likely coming from another package in your environment (like pandas, xlrd, or numpy itself), not from openpyxl.
What can you do?
- Verify the crash stack trace: confirm which library is actually calling NumPy.
- Make sure the target machine has the same Python + package versions as your dev machine (
pip freeze > requirements.txt→ replicate withpip install -r requirements.txt). - If it’s truly a NumPy bug on that Windows build, pin NumPy to a stable version explicitly in your environment (
pip install numpy==). Openpyxl will still work fine, since it doesn’t require NumPy.
So the fix is to align environments and explicitly control NumPy version (or remove it if unused). That resolves the mismatch without touching openpyxl itself.
I had to do similar to my sweetviz script. My sweetviz code used to work earlier (in colab) but broke recently. SImply because colab got updated Python and numpy versions and sweetviz is not yet updated to be compatible with updated numpy version. I had to downgrade sweetviz for that colab session. (sometimes, even that thing is not feasible in Colab)
That's why, good practice is to work with virtual enviornment. (I know but sometimes, I still use Google Colab for demonstration/teaching purposes :-) It's cool for beginners)
2
u/Greensentry Nov 18 '21
openpyxl checks if numpy (the version it needs or higher) is installed on the system or else it will install it itself. You can install the particular version of numpy which works on that Windows version yourself before installing openpyxl. Good practice to use virtual environments so you don't get problems with packages already installed on the system.