Use of the openpyxl library

Hello, I work in a Windows environment and use the openpyxl library to read and manipulate Excel files.
When installing the application on a new server, I notice that this library completely blocks the app’s startup: at launch, after a few moments, I am presented with the DOS shell prompt again without any error message.
To isolate the problem, I wrote the following code that shows the same behavior: when encountering the “import openpyxl” instruction, the app stops and returns to the system prompt. I would like to receive suggestions. Thank you.
Would you like me to offer some advice on troubleshooting this issue with openpyxl?

import logging
logging.basicConfig(level=logging.DEBUG)
print("Prima di import")
try:
    import openpyxl
    logging.debug("Ok")
except Exception as e:
    logging.error(f"Error during openpyxl import: {e}")

What is the traceback when you import openpyxl?

Your try/except code is preventing this key information from being printed.

Hi,

what is the message printout (the exception e per @barry-scott ):

That supresses the traceback which is the important information we need to see.
The {e} will not be enough information as you do not where the expection was raised.

1 Like

Even without including the import in the error control block, the mere instruction ‘import openpyxl’ causes the execution to terminate without any error message. Even when running the app with the -v (verbose) option, no abnormal message is indicated. Everything just stops

Does the -v output show where openpyxl is loaded from?

# E:\test\venv\lib\site-packages\openpyxl\__pycache__\__init__.cpython-310.pyc matches E:\test\venv\lib\site-packages\openpyxl\__init__.py
# code object from 'E:\\test\\venv\\lib\\site-packages\\openpyxl\\__pycache__\\__init__.cpython-310.pyc'
# E:\test\venv\lib\site-packages\openpyxl\compat\__pycache__\__init__.cpython-310.pyc matches E:\test\venv\lib\site-packages\openpyxl\compat\__init__.py
# code object from 'E:\\test\\venv\\lib\\site-packages\\openpyxl\\compat\\__pycache__\\__init__.cpython-310.pyc'
# E:\test\venv\lib\site-packages\openpyxl\compat\__pycache__\numbers.cpython-310.pyc matches E:\test\venv\lib\site-packages\openpyxl\compat\numbers.py
# code object from 'E:\\test\\venv\\lib\\site-packages\\openpyxl\\compat\\__pycache__\\numbers.cpython-310.pyc'

After that line the next thing you see if the CMD prompt?

Not immediately. Other imports are executed, and the last lines are:

# E:\uData\venv\lib\site-packages\numpy\ma\__pycache__\extras.cpython-310.pyc matches E:\uData\venv\lib\site-packages\numpy\ma\extras.py
# code object from 'E:\\uData\\venv\\lib\\site-packages\\numpy\\ma\\__pycache__\\extras.cpython-310.pyc'
import 'numpy.ma.extras' # <_frozen_importlib_external.SourceFileLoader object at 0x0785AF28>
import 'numpy.ma' # <_frozen_importlib_external.SourceFileLoader object at 0x07797928>

It would seem that this maybe the problem module.

Can you test numpy imports and see if that also breaks?