[Python] Python cannot import openpyxl

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I am running Windows 7 and using Python 2.7.

    I have installed openpyxl using easy_install. It looks like the installation was successful. I changed the directory and fired up Python.

    >>> import openpyxl
    >>>


    So, this should mean that Python is able to find openpyxl. However, when I execute a simple test program excell_tutorial1.py and run it, I get the following:

    Traceback (most recent call last):
    File "C:/Python27/playground/excell_tutorial1.py", line 7, in <module>
    from openpyxl import Workbook
    ImportError: No module named openpyxl


    Very confusing! It could find it in prompt line but not in the program!

    import os, sys

    the_module ="C:\\Python27\\Lib\\site-packages\\openpyxl-2.3.3-py2.7.egg\\openpyxl"


    if the_module not in sys.path:
    sys.path.append(the_module)

    if the_module in sys.path:
    print sys.path.index(the_module)
    print sys.path[18]


    so, this gives me:

    18
    C:\Python27\Lib\site-packages\openpyxl-2.3.3-py2.7.egg\openpyxl


    Anyone can think of what the problem might be?

    Much appreciated

    Continue reading...

Compartilhe esta Página