New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error building executable using pyinstaller #7052

Open
lzkelley opened this Issue Jan 8, 2018 · 13 comments

Comments

Projects
None yet
5 participants
@lzkelley
Contributor

lzkelley commented Jan 8, 2018

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?

@pllim pllim added the installation label Jan 8, 2018

@pllim

This comment has been minimized.

Member

pllim commented Jan 8, 2018

Re: cosmology -- Discussion to separate it out comes up once in a while (e.g., #6567) but for now, the consensus is to keep it in the core.

@astrofrog

This comment has been minimized.

Member

astrofrog commented Jan 8, 2018

@lzkelley - can you try with the latest developer version of astropy, without the 'six' trick? (since six is no longer required/included).

@lzkelley

This comment has been minimized.

Contributor

lzkelley commented Jan 8, 2018

Ran into a (seemingly) unrelated pyinstaller error on a different system (standard system is in for repairs at the moment)... will update when I can try again.

@astrofrog

This comment has been minimized.

Member

astrofrog commented Jan 8, 2018

I just tried running:

pyinstaller -F app.py 

with the latest astropy, and the six issue is gone but this is still a problem:

Traceback (most recent call last):
  File "app.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "astropy/__init__.py", line 122, in <module>
  File "astropy/__init__.py", line 129, in Conf
  File "astropy/config/configuration.py", line 229, in __init__
RuntimeError: Cannot automatically determine get_config module, because it is not called from inside a valid module
[28432] Failed to execute script app
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

(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.

@lzkelley

This comment has been minimized.

Contributor

lzkelley commented Jan 9, 2018

Thanks @astrofrog, the @maartenbreddels approach does seem to work (at least in python3.5). I would volunteer for reapplying #960, but I really have no idea what it's doing...

@lzkelley

This comment has been minimized.

Contributor

lzkelley commented Jan 15, 2018

@astrofrog I'm trying the same approach in python2.7, but in that case I can't even get the dev version of astropy to install... is that a separate problem?

$ pip install git+https://github.com/astropy/astropy.git@v3.0rc1

Collecting git+https://github.com/astropy/astropy.git@v3.0rc1
  Cloning https://github.com/astropy/astropy.git (to v3.0rc1) to /private/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/pip-W7jspE-build
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/pip-W7jspE-build/setup.py", line 8, in <module>
        import ah_bootstrap
      File "ah_bootstrap.py", line 885, in <module>
        BOOTSTRAPPER = _Bootstrapper.main()
      File "ah_bootstrap.py", line 221, in main
        bootstrapper.run()
      File "ah_bootstrap.py", line 307, in run
        dist = method()
      File "ah_bootstrap.py", line 365, in get_local_directory_dist
        dist = self._directory_import()
      File "ah_bootstrap.py", line 462, in _directory_import
        ['egg_info'])
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 253, in run_setup
        raise
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
        self.gen.throw(type, value, traceback)
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
        yield
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
        self.gen.throw(type, value, traceback)
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 166, in save_modules
        saved_exc.resume()
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 141, in resume
        six.reraise(type, exc, self._tb)
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 154, in save_modules
        yield saved
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
        yield
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 250, in run_setup
        _execfile(setup_script, ns)
      File "/Users/lzkelley/Programs/electron/test-cosmo/src/test-env-27/lib/python2.7/site-packages/setuptools/sandbox.py", line 45, in _execfile
        exec(code, globals, locals)
      File "/private/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/pip-W7jspE-build/astropy_helpers/setup.py", line 7, in <module>
        from astropy_helpers.setup_helpers import register_commands, get_package_info
      File "/private/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/pip-W7jspE-build/astropy_helpers/astropy_helpers/__init__.py", line 46, in <module>
        import builtins
    ImportError: No module named builtins

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/wr/_dhmn18x1dj6t8ytjjd9rsxh0000gn/T/pip-W7jspE-build/
@astrofrog

This comment has been minimized.

Member

astrofrog commented Jan 15, 2018

@lzkelley - the developer version of Astropy now only supports Python 3

@fockez

This comment has been minimized.

Contributor

fockez commented Feb 12, 2018

I wait for the astropy 3.0 for a long time, because it no longer relies on six module. I use pyinstaller on windows to pack the app with astropy 30.rc2, and it also goes wrong.
The log is attached.
astropy.zip

@pllim

This comment has been minimized.

Member

pllim commented Feb 12, 2018

Seems like a different error than above, so... progress? 😬

  File "c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\ast.py", line 263, in generic_visit
    self.visit(value)
  File "c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\ast.py", line 253, in visit
    return visitor(node)
RecursionError: maximum recursion depth exceeded
@fockez

This comment has been minimized.

Contributor

fockez commented Feb 15, 2018

I don't know which one causes the problem, pyinstaller or astropy. pyinstaller/pyinstaller#3061, this thread said using the latest dev version should be ok. But no luck with astropy.

@pllim

This comment has been minimized.

Member

pllim commented Feb 15, 2018

Since I see some python2.7 is traceback above, I just want to point out that you can only use Python 3 with Astropy 3.0.

@fockez

This comment has been minimized.

Contributor

fockez commented Feb 17, 2018

I just mean that pyinstaller community has the similar error report. for me, i use anaconda3 with python3.6. I know that astropy 3.0 can only work with python3, I hope this will be better bacause with the former version, the six module always cause problem.

@lamourj

This comment has been minimized.

lamourj commented May 30, 2018

I don't have a solution, but a potential workaround which worked for me was the following:
In the *.spec file, add:

import astropy
astropy_path, = astropy.__path__

Then in the Analysis, add (astropy_path, 'astropy') into the datas list and 'astropy' in the excludes list.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment