ImportError: cannot import name get_column_letter

charsi picture charsi · Apr 19, 2016 · Viewed 25.7k times · Source

I am able to use openpyxl as an import in my code. But when I try to do the following:

from openpyxl.cell import get_column_letter 

I get the following error:

ImportError: cannot import name get_column_letter

I am using python 2.7. I have installed it using easy_install. Tried searching for this issue but couldn't find anything related to it.

Answer

Abbas picture Abbas · Apr 19, 2016

The function get_column_letter has been relocated in Openpyxl version 2.4 from openpyxl.cell to openpyxl.utils.

The current import is: from openpyxl.utils import get_column_letter

If you want to do not know which version the end-user has, you can use the following code:

try: 
    from openpyxl.cell import get_column_letter
except ImportError:
    from openpyxl.utils import get_column_letter