cannot import workbook in openpyxl

前端 未结 2 1421
慢半拍i
慢半拍i 2020-12-06 15:25

I have installed openpyxl in ubuntu.
now I am running the openpyxl with xlsx files.

While importing the module, it gives me the following error.

         


        
相关标签:
2条回答
  • 2020-12-06 15:40

    I think you want:

    from openpyxl import workbook # not Workbook
    

    Note the capitalization of the name here.

    0 讨论(0)
  • 2020-12-06 16:00

    I answer your second problem, because I found the solution (as though the cause of the first one is the same).

    I think the problem is caused because the version that you have installed on your Ubuntu is not the latest version (1.5.7 at the moment). And the official documentation is based on the latest one.

    For example the version of openpyxl provided on my Ubuntu 11.10 is not the latest, but 1.5.3, and if you use this syntax (taken from here: https://bitbucket.org/ericgazoni/openpyxl/wiki/Home), the commands work:

    from openpyl.workbook import Workbook
    

    for the Workbook and for load_workbook:

    from openpyxl.reader.excel import load_workbook
    

    But you can also install the latest one with easy_install:

    $ sudo easy_install openpyxl
    

    And to install easy_install, read this answer: https://askubuntu.com/questions/27519/can-i-use-easy-install

    0 讨论(0)
提交回复
热议问题