So I bought a new laptop and did a fresh install of python 3.7.3 through the installer for Windows 10. Afterwards, I updated my pip and then used pip install for Openpyxl. I tried running my code that works on other computers but on this setup, its giving me
ImportError: cannot import name 'Worksheet' from 'openpyxl.worksheet' (C:\\Users\\James\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\openpyxl\\worksheet\\__init__.py)
Anyone have any idea why I would get this error? This is the line of code for reference.
from openpyxl.worksheet import Worksheet
Expanded answer from my comment above:
the error you're seeing is because of capitalization of the 2nd "worksheet'. use from openpyxl.worksheet import worksheet" (note all lowercase)
the Worksheet
class is buried under two levels of worksheet
. This is because the openpyxl
package has a package and a module, both named worksheet
. So to access it, use from openpyxl.worksheet.worksheet import Worksheet
.
Of course, one could use from openpyxl.worksheet import worksheet
but then will need to prepend Worksheet
with worksheet
everywhere in your code, like so: worksheet.Worksheet
.
Hope this helps.
I'm hoping this worked below:
from openpyxl import worksheet
I apologize I initially thought
from openpyl.workbook import Workbook
might help
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.