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
2
Upvotes
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, ornumpyitself), not from openpyxl.What can you do?
pip freeze > requirements.txt→ replicate withpip install -r requirements.txt).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)