Skip to content

astropy.io: ImportError: No module named _bz2  #5967

Closed

Description

@blazar716

Hello, I am using Debian 8.7 and I got the following import error while importing fits from the astropy.io (astropy Version: 1.3.2).

from astropy.io import fits
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/io/fits/__init__.py", line 70, in <module>
    from . import convenience
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/io/fits/convenience.py", line 64, in <module>
    from .file import FILE_MODES, _File
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/io/fits/file.py", line 5, in <module>
    import bz2
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python/bz2.py", line 20, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named _bz2

Similarly, astropy.test() gives me the following errors.

>>> astropy.test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/utils/decorators.py", line 874, in test
    func = make_function_with_signature(func, name=name, **wrapped_args)
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/tests/runner.py", line 224, in test
    return runner.run_tests(**kwargs)
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/tests/runner.py", line 516, in run_tests
    from ..table import Table  # pylint: disable=W0611
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/table/__init__.py", line 59, in <module>
    from ..io.fits import connect
  File "/gbdata/ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10/lib/python2.7/site-packages/astropy/io/fits/__init__.py", line 16, in <module>
    from . import py3compat
ImportError: cannot import name py3compat

Any help will be highly appreciated.

Activity

  1. MSeifert04 commented on Apr 17, 2017

    @MSeifert04
    Contributor

    it seems you don't have the bz2 module installed. In most python distributions it's built by default which is why it isn't a guarded import.

    Do you have the libbz2 (or libbz2-dev) library installed?

    EDIT:

    How exactly did you install python? ScienceTools-v10r0p5-fssc-20150518-/x86_64-unknown-linux-gnu-libc2.19-10 sounds like a bundled package and the "unknown-linux" part seems odd (maybe indicates that it wasn't setup properly).

  2. blazar716 commented on Apr 17, 2017

    @blazar716
    Author

    Thank you for your comment.

    I have libbz2-dev already installed, as shown by the terminal commands below.

    user@user$ sudo apt-get install libbz2-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    libbz2-dev is already the newest version.

    I should have probably mentioned earlier that I am using the python which is a part of ScienceTools, and I think the "unknown-linux" part is ok because this is how they name their packages. Besides all their python modules work perfectly fine except astropy which I installed using the pip as a part of their python.

  3. pllim commented on Apr 17, 2017

    @pllim
    Member

    I feel like this should be addressed by ScienceTools developers, not here.

  4. bsipocz commented on Apr 17, 2017

    @bsipocz
    Member

    @blazar716 - I'm not familiar with this ScienceTools at all, but it seems that it's somewhat distinct from your system packages. First I would check the PATH and PYTHONPATH, and that bz2 is indeed accessible when using your ScienceTools python.
    Also, I agree with @pllim, that this seems to be something we can't do anything about here, and that needs to be addressed within ScienceTools.

  5. MSeifert04 commented on Apr 17, 2017

    @MSeifert04
    Contributor

    @bsipocz We could do something. I'm not saying that we should - but we could "guard" the bz2 imports and treat it as "optional" dependency. It has been a recurring problem (i.e. 0, 1) that some pythons don't have bz2 build by default, either because the python isn't setup correctly or because some system libraries like libbz2 are missing.

    The reason for the missing bz2 is very likely upstream (or a path-issue) but failing to import astropy probably isn't the best way to handle it.

  6. blazar716 commented on Apr 17, 2017

    @blazar716
    Author

    Thank you all, for your helpful comments.

  7. pllim commented on Apr 18, 2017

    @pllim
    Member

    @MSeifert04 , did you just volunteered for a PR? 😉

  8. dhomeier commented on Nov 19, 2019

    @dhomeier
    Contributor

    @MSeifert04 this has just popped up again, and while the Python installation in question is probably not the one one should work with, builds without bz2 support certainly still exist.

    From a quick glance the only places (apart from several tests) that seem to unconditionally import bz2 are io.fits's file.py and hdu/hdulist.py, as they need it for automatic detection of bz2.BZ2File types. But that could be easily wrapped around, I think - that way io would not recognise bzip2'ed FITS files, or only by their suffix, but it could not transparently read them anyway.
    Also all the tests except for io.fits specifically consider the HAS_BZ2=False case, so I'd say there clearly exists a philosophy of supporting these systems.

  9. saimn commented on Nov 21, 2019

    @saimn
    Contributor

    Since bz2 is an optional dependency for Python I think it makes sense to treat it as an optional dependency in astropy. Reopening the issue then, since @MSeifert04 agreed two years ago ;)

  10. reopened this on Nov 21, 2019
  11. dhomeier commented on Nov 21, 2019

    @dhomeier
    Contributor

    OK, I am preparing a PR.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions