Skip to content

Error building executable using pyinstaller #7052

@lzkelley

Description

@lzkelley

Building executables which include astropy seem to have a history of issues (e.g. #960 (comment)). Initially I was getting an,
ImportError: Astropy requires the 'six' module of minimum version 1.10, which I solved by using a trick given in the above PR:

I was able to get this to work using PyInstaller with the following pyinstaller options --exclude-module astropy and --add-data path_to/astropy:astropy -- @fridgerator

Now I get the new error:

Traceback (most recent call last):
  File "pyapi.py", line 10, in <module>
    import cosmopy
  File "/Users/lzkelley/Programs/cosmo/ve_test/vetest/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/cosmopy/__init__.py", line 9, in <module>
  File "/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/_MEIhGawWS/astropy/constants/__init__.py", line 28, in <module>
    from .constant import Constant, EMConstant
  File "/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/_MEIhGawWS/astropy/constants/constant.py", line 11, in <module>
    from ..units.core import Unit, UnitsError
  File "/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/_MEIhGawWS/astropy/units/__init__.py", line 14, in <module>
    from .core import *
  File "/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/_MEIhGawWS/astropy/units/core.py", line 23, in <module>
    from .utils import (is_effectively_unity, sanitize_scale, validate_power,
  File "/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/_MEIhGawWS/astropy/units/utils.py", line 16, in <module>
    from fractions import Fraction
ImportError: No module named 'fractions'
[2338] Failed to execute script pyapi

I'm using a virtualenv named vetest in the directory ve_test, trying to run with the command:
pyinstaller -F pyapi.py --exclude-module astropy --add-data /Users/lzkelley/Programs/cosmo/ve_test/vetest/lib/python3.5/site-packages/astropy:astropy

The full output from pyinstaller is attached.

out.txt


An additional issue is that the resulting executable is >200MB, is that normal? The application I'm trying to package is really just using the astropy.cosmology.LambdaCDM class. Might there be a better way to include that alone?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions