astropy: Error building executable using pyinstaller
Building executables which include astropy
seem to have a history of issues (e.g. https://github.com/astropy/astropy/pull/960#issuecomment-355678708). 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.
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?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 24 (15 by maintainers)
Commits related to this issue
- build: try to fix build with astropy as per https://github.com/astropy/astropy/issues/7052 — committed to FCS-analysis/PyScanFCS by paulmueller 5 years ago
- build: move to latest version of astropy and pyinstaller to check https://github.com/astropy/astropy/issues/7052 — committed to FCS-analysis/PyScanFCS by paulmueller 4 years ago
yes, works!
I don’t have a solution, but a potential workaround which worked for me was the following: In the
*.spec
file, add:Then in the Analysis, add
(astropy_path, 'astropy')
into thedatas
list and'astropy'
in theexcludes
list.Hope this helps.
@lzkelley - the developer version of Astropy now only supports Python 3
I just tried running:
with the latest astropy, and the six issue is gone but this is still a problem:
(this error was discussed extensively in #960)
But it might work fine if doing: https://github.com/maartenbreddels/frozen_astropy
It’d be nice in the long run to not require that and have it work ‘out of the box’. For that to work, I think someone needs to go through the changes in #960 and apply the ones that are still relevant.
@burhankhanlodhy thanks this worked for me.
@astrofrog Shouldn’t it be possible to add this to the PyInstaller hook? Otherwise this hook would somehow miss its intended purpose.
Thanks @lamourj for the workaround. I had also to add the astropy dependencies as hiddenimports explicitly though: