Skip to content

Can't build with Python 3.6: KeyError: '_unit' #7068

Closed

Description

@olebole

astropy_3.0~rc1-1_amd64.txt
When I try to compile 3.0rc1 with Python 3.6, I get the following error:

I: pybuild base:184: /usr/bin/python3 setup.py build --use-system-libraries
Traceback (most recent call last):
  File "/build/astropy-3.0~rc1/astropy/utils/decorators.py", line 706, in __get__
    return obj.__dict__[self._key]
KeyError: '_unit'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 466, in _do_parse
    return cls._parse_unit(s, detailed_exception=False)
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 446, in _parse_unit
    raise ValueError()
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/astropy-3.0~rc1/astropy/units/core.py", line 1784, in __call__
    return f.parse(s)
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 453, in parse
    result = cls._do_parse(s, debug=debug)
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 469, in _do_parse
    return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
  File "/build/astropy-3.0~rc1/astropy/utils/decorators.py", line 628, in __get__
    val = self.fget.__wrapped__(objtype)
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 99, in _lexer
    return cls._make_lexer()
  File "/build/astropy-3.0~rc1/astropy/units/format/generic.py", line 159, in _make_lexer
    reflags=re.UNICODE)
  File "/usr/lib/python3/dist-packages/ply/lex.py", line 921, in lex
    lexobj.readtab(lextab, ldict)
  File "/usr/lib/python3/dist-packages/ply/lex.py", line 215, in readtab
    exec('import %s' % tabfile)
  File "<string>", line 1, in <module>
  File "/build/astropy-3.0~rc1/astropy/units/format/generic_lextab.py", line 4
    _lexreflags   = <RegexFlag.UNICODE: 32>
                    ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 42, in <module>
    package_info = get_package_info()
  File "/usr/lib/python3/dist-packages/astropy_helpers/setup_helpers.py", line 388, in get_package_info
    ext_modules.extend(setuppkg.get_extensions())
  File "astropy/wcs/setup_package.py", line 239, in get_extensions
    generate_c_docstrings()
  File "astropy/wcs/setup_package.py", line 116, in generate_c_docstrings
    from astropy.wcs import docstrings
  File "/build/astropy-3.0~rc1/astropy/wcs/__init__.py", line 29, in <module>
    from .wcs import *
  File "/build/astropy-3.0~rc1/astropy/wcs/wcs.py", line 47, in <module>
    from ..io import fits
  File "/build/astropy-3.0~rc1/astropy/io/fits/__init__.py", line 70, in <module>
    from . import convenience
  File "/build/astropy-3.0~rc1/astropy/io/fits/convenience.py", line 72, in <module>
    from ...units import Unit
  File "/build/astropy-3.0~rc1/astropy/units/__init__.py", line 15, in <module>
    from .decorators import *
  File "/build/astropy-3.0~rc1/astropy/units/decorators.py", line 11, in <module>
    from .physical import _unit_physical_mapping
  File "/build/astropy-3.0~rc1/astropy/units/physical.py", line 15, in <module>
    from . import astrophys
  File "/build/astropy-3.0~rc1/astropy/units/astrophys.py", line 44, in <module>
    def_unit(['lyr', 'lightyear'], (_si.c * si.yr).to(si.m),
  File "/build/astropy-3.0~rc1/astropy/constants/constant.py", line 42, in wrapper
    self.unit.to(inst.unit)
  File "/build/astropy-3.0~rc1/astropy/units/quantity.py", line 912, in unit
    return self._unit
  File "/build/astropy-3.0~rc1/astropy/utils/decorators.py", line 708, in __get__
    val = self.fget(obj)
  File "/build/astropy-3.0~rc1/astropy/constants/constant.py", line 165, in _unit
    return Unit(self._unit_string)
  File "/build/astropy-3.0~rc1/astropy/units/core.py", line 1798, in __call__
    raise ValueError(msg)
ValueError: 'm / (s)' did not parse as unit: invalid syntax (generic_lextab.py, line 4)

The problem also appears with 2.0.3, however. This appears during a Debian build. Full build log is attached.

Activity

  1. pllim commented on Jan 11, 2018

    @pllim
    Member

    Do you really need --use-system-libraries? I tried with that option and I got error about erfa.h. However, not using that option gave me successful build.

  2. added and removed on Jan 11, 2018
  3. olebole commented on Jan 11, 2018

    @olebole
    MemberAuthor

    Yes, I need --use-system-libraries, since for the Debian package, we don't want to use the libraries that are shipped with astropy. This flag was specifically made for distributors (also for Fedora).

  4. saimn commented on Jan 11, 2018

    @saimn
    Contributor

    This could be due to some difference between the bundled package and Debian's one, I was thinking about ply since it is used for astropy/units/format/generic_lextab.py but it seems to be the same version (3.9).

  5. MSeifert04 commented on Jan 11, 2018

    @MSeifert04
    Contributor

    That's odd. The SyntaxError is really interesting (and scary) but I wonder why that stacktrace originates from generate_c_docstrings() ...

  6. olebole commented on Jan 12, 2018

    @olebole
    MemberAuthor

    @saimn I run into the same problems when I use the ply provided by astropy. The problem seems to be the creation of astropy/units/format/generic_lextab.py -- I remove this from the file (and generic_parsetab.py before start building (since I need to have it created from source).
    This also explains, why I did not discover this before: until now, I first created the Python 2 version (which went nicely); and in this step also generic_lextab.py is created. Then, wen creating the Python 3 package, this file is already there.
    The problem seems to be that generic_lextab.py and generic_parsetab.py is since quite a time not generated, but (at least additionally) manually edited. I am not sure whether I understand this fully, but #1112 (and the manual edits) suggest that I should stay with the generated file, right?

  7. saimn commented on Jan 12, 2018

    @saimn
    Contributor

    @olebole - Looking at old issues, it seems indeed that there is a script that modifies the generated files for py2/py3 compatibility (#4300). I don't know much more about this, not sure who does, @eteq or @mhvk maybe ?
    BTW, it may be something to revisit now that we support py3 only ?

  8. mhvk commented on Jan 12, 2018

    @mhvk
    Contributor

    I mostly remember being caught out by the generated files, and that there was a somewhat similar issue for angles - #5728 - maybe @bsipocz knows more? Ideally, our source distribution does not contain these files and they get generated correctly by setup.py install.

  9. astrofrog commented on Jan 30, 2018

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

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