3

My traceback from running pandas takes me to:
site-packages\pandas\io\excel.py line 58, in get_writer AttributeError: 'module' object has no attribute '__version__'

I found this link to a git issue in the PyInstaller repo https://github.com/pyinstaller/pyinstaller/issues/1890 and found my openpyxl version, manually added it into the get_writer method like so:

def get_writer(engine_name):
    if engine_name == 'openpyxl':
        try:
            import openpyxl
            #remove when conda update available
            openpyxl.__version__ = '2.3.2'
            # with version-less openpyxl engine
            # make sure we make the intelligent choice for the user
            if LooseVersion(openpyxl.__version__) < '2.0.0':
                return _writers['openpyxl1']
            elif LooseVersion(openpyxl.__version__) < '2.2.0':
                return _writers['openpyxl20']
            else:
                return _writers['openpyxl22']
        except ImportError:
            # fall through to normal exception handling below
            pass

    try:
        return _writers[engine_name]
    except KeyError:
        raise ValueError("No Excel writer '%s'" % engine_name)

Still no dice. The line number given in the error traceback doesn't even change. I then updated the openpyxl version to 2.3.5, still receiving the error. The openpyxl init file has a version variable in it:

try:
    here = os.path.abspath(os.path.dirname(__file__))
    src_file = os.path.join(here, ".constants.json")
    with open(src_file) as src:
        constants = json.load(src)
        __author__ = constants['__author__']
        __author_email__ = constants["__author_email__"]
        __license__ = constants["__license__"]
        __maintainer_email__ = constants["__maintainer_email__"]
        __url__ = constants["__url__"]
        __version__ = constants["__version__"]
except IOError:
    # packaged
    pass

Any known or potential fixes or workarounds?

  • 1
    i don't think that this has anything to do with Pandas but how you installed openpyxl. The only installation method that is supported is using pip. – Charlie Clark Aug 30 '16 at 19:43
  • @CharlieClark I have it installed through both pip and an Anaconda environment, both are at the 2.3.5 version spec for openpyxl. I wasn't aware that regarding pip. – Michael J Caboose Aug 30 '16 at 23:44
  • If openpyxl is installed using pip then the metadata including the version will exposed within the package. – Charlie Clark Aug 31 '16 at 06:23

3 Answers3

2

Edits were not making an impact because the process was compiled into an exe that these modules were running through. Exported the sections I needed outside of my anaconda environment and now the process works without a hitch.

2

I will add my workaround to this discussion as I was having the same problem using openpyxl 2.4.0 and maybe a few others are stuck too. I found that to create a .exe file you have to revert to an older version of openpyxl. To do so:

  1. Open the command prompt and uninstall openpyxl with 'pip uninstall openpyxl'
  2. Reinstall openpyxl using an older version 'pip install openpyxl==2.3.5'

Now you should be able to create your .exe file using py2exe, cx_freeze, etc.

Marc vT
  • 496
  • 3
  • 12
2

This is my fix: go to your openpyxl site-package folder (for me it's: C:\Python27\Lib\site-packages\openpyxl). Copy all variables in your .constant.json file directly into the _ init _.py file, so it looks like:

import json
import os
__author__= "See AUTHORS"
__author_email__= "eric.gazoni@gmail.com"
__license__= "MIT/Expat",
__maintainer_email__= "openpyxl-users@googlegroups.com"
__url__= "http://openpyxl.readthedocs.org"
__version__= "2.4.0"
try:
    here = os.path.abspath(os.path.dirname(__file__))
Stella
  • 139
  • 3
  • 14