ImportError: cannot import name 'Workbook'

2,281 views
Skip to first unread message

benneb...@gmail.com

unread,
Jul 23, 2017, 8:21:34 AM7/23/17
to openpyxl-users
I'm sure this is only a small thing, but at the moment I'm not able to solve this issue.

I'm trying to use the openpyxl package in order to manipulate some excel sheets.
When I type following into the python shell, everything works :

>>> from openpyxl import Workbook
>>> wb = Workbook()
>>> ws = wb.active

But as soon as I try to create a script with following input, it doesn't work :

from openpyxl import Workbook
wb = Workbook()
ws = wb.active

I always get following message :

Traceback (most recent call last):
  File "C:\Users\bla\AppData\Local\Programs\Python\Python36\Scripts\openpyxl.py", line 1, in <module>
    from openpyxl import Workbook
  File "C:\Users\bla\AppData\Local\Programs\Python\Python36\Scripts\openpyxl.py", line 1, in <module>
    from openpyxl import Workbook
ImportError: cannot import name 'Workbook'

I'am using Python 3.6.2 on a Windows 10 OS, installed the openpyxl package as recommended with 'pip install openpyxl'.

I hope someone can help me soon.

Thanks in advance.

aimer...@gmail.com

unread,
May 11, 2018, 11:37:41 PM5/11/18
to openpyxl-users
I encountered the same question in Ubuntu OS.

Hope anyone can help us.

Thanks.

在 2017年7月23日星期日 UTC+8下午8:21:34,benneb...@gmail.com写道:

tasfiq....@gmail.com

unread,
Jan 11, 2020, 1:09:17 AM1/11/20
to openpyxl-users
Facing same problem here. Don't know how to solve the problem.

aimer...@gmail.com

unread,
Jan 14, 2020, 8:52:33 PM1/14/20
to openpyxl-users
Maybe you can use the module in this way:

from openpyxl import load_workbook

try:
self.wb = load_workbook(xlsx)
except Exception as e:
logger.error(repr(e))
raise Exception("Exception takes place when load_workbook {} {}".format(xlsx, repr(e)))

self.sheetnames = self.wb.sheetnames
self.now_sheet = self.wb.active

If anymore help, just raise it.
Aimery


在 2020年1月11日星期六 UTC+8下午2:09:17,tasfiq....@gmail.com写道:

Pedro Dardengo Mesquita

unread,
Feb 3, 2021, 8:35:36 PM2/3/21
to openpyxl-users
This may be due to the name you have put in your file, I'm not sure which one you chose, but if you chose openpyxl.py thats a poor choice.
This may seem obvious... but don't name your file openpyxl.py
Otherwise the it will try to load the file not the module...

Name it, openpyxl_tutorial.py, now the import function should work just fine.

jolie jin

unread,
Jan 18, 2022, 5:11:06 AM1/18/22
to openpyxl-users
Thank you

Alexander Khamaganov

unread,
Feb 3, 2023, 5:23:54 PM2/3/23
to openpyxl-users
You best of the best!!!)

четверг, 4 февраля 2021 г. в 03:35:36 UTC+2, Pedro Dardengo Mesquita:

Parvateesam Naidu

unread,
Apr 8, 2024, 11:40:52 PMApr 8
to openpyxl-users

You saved my time..

but if you chose openpyxl.py thats a poor choice.
This may seem obvious... but don't name your file openpyxl.py
Otherwise the it will try to load the file not the module...


exactly this is the problem I went into..thanks for your inputs

Reply all
Reply to author
Forward
0 new messages