No module named builtins

前端 未结 4 495
离开以前
离开以前 2020-12-29 03:12

I\'m trying to convert my .py script into an executable using py2exe. I\'ve had a number of issues so far that have been largely addressed by the \"options\" in the setup fi

4条回答
  •  -上瘾入骨i
    2020-12-29 03:21

    I finally got this working. It turned out that I had some errors in the original setup file, some of which were outright dumb, and some simply reflected my lack of understanding of how the parameters of the setup command works. I will add that this latter class of errors was only resolved with some Sherlock Holmes-style sleuthing and plain old trial and error. By that I mean that I have still not found any documentation that calls out the meaning and usage of the parameters of the setup command. If anyone has that info and could pass it along that would be much appreciated.

    With that as background, here is the answer:

    There were 2 basic problems:

    1. The list of packages in the above setup file was woefully incomplete. I am still not certain that the rule is that you have to list every single package that your program relies upon, and some which it may rely upon that you didn't know about (e.g. pytz). But when I did that, I had something at that point that I could eventually get to work.

    2. The error message in the above original question sort of looks like my program had a dependency on a thing called "patsy". This confused me because I had no idea what that was. It turns out that statsmodels (which is core to my project) has a dependency on patsy, so it needed to be included in the "packages" list.

    Below is the setup file that ended up working. I hope this description of the logic behind the fix turns out to be helpful to others facing the same kind of problem.

    from distutils.core import setup
    import py2exe
    
    from distutils.filelist import findall
    import os
    import matplotlib
    matplotlibdatadir = matplotlib.get_data_path()
    matplotlibdata = findall(matplotlibdatadir)
    
    
    
    setup(
        console=['DET14.py'],
        options={
                 'py2exe': {
                        'packages' : ['matplotlib', 'pytz','easygui',\
                                      'statsmodels','pandas','patsy'],
                        'dll_excludes':['MSVCP90.DLL',
                                        'libgdk-win32-2.0-0.dll',
                                        'libgobject-2.0-0.dll',
                                        'libgdk_pixbuf-2.0-0.dll'],
                        'includes':['scipy.sparse.csgraph._validation',
                            'scipy.special._ufuncs_cxx']
                       }
            },
        data_files=matplotlib.get_py2exe_datafiles()
    )
    

提交回复
热议问题