Repository navigation
Closed
Labels
Description
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 _bz2Similarly, 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 py3compatAny help will be highly appreciated.
Activity
MSeifert04 commentedon Apr 17, 2017
it seems you don't have the
bz2module 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-10sounds like a bundled package and the "unknown-linux" part seems odd (maybe indicates that it wasn't setup properly).blazar716 commentedon Apr 17, 2017
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.
pllim commentedon Apr 17, 2017
I feel like this should be addressed by ScienceTools developers, not here.
bsipocz commentedon Apr 17, 2017
@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.
MSeifert04 commentedon Apr 17, 2017
@bsipocz We could do something. I'm not saying that we should - but we could "guard" the
bz2imports and treat it as "optional" dependency. It has been a recurring problem (i.e. 0, 1) that some pythons don't havebz2build by default, either because the python isn't setup correctly or because some system libraries likelibbz2are missing.The reason for the missing
bz2is very likely upstream (or a path-issue) but failing to importastropyprobably isn't the best way to handle it.blazar716 commentedon Apr 17, 2017
Thank you all, for your helpful comments.
pllim commentedon Apr 18, 2017
@MSeifert04 , did you just volunteered for a PR? 😉
dhomeier commentedon Nov 19, 2019
@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
bz2support certainly still exist.From a quick glance the only places (apart from several tests) that seem to unconditionally
import bz2areio.fits'sfile.pyandhdu/hdulist.py, as they need it for automatic detection ofbz2.BZ2Filetypes. But that could be easily wrapped around, I think - that wayiowould 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.fitsspecifically consider theHAS_BZ2=Falsecase, so I'd say there clearly exists a philosophy of supporting these systems.saimn commentedon Nov 21, 2019
Since
bz2is 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 ;)dhomeier commentedon Nov 21, 2019
OK, I am preparing a PR.