astropy: Astropy import conflicts with Spyder User Module Reloader
Something in the import framework fails when importing astropy multiple times in a Spyder Ipython console, using the builtin runfile() with the reload option of its User Module Reloader (UMR) enabled. Minimal way to reproduce the issue on various versions from Spyder 2.3.5.2-3.1.2, Ipython 3.2.2-5.1.0 and Astropy 1.1.1-2.0.5 under SuSe Linux or Ubuntu:
Python 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC]
Type "copyright", "credits" or "license" for more information.
IPython 3.2.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
In [1]: cd ~/routines/python/cosmo
/data/derek/routines/python/cosmo
In [2]: cat ap.py
# Test script for astropy reload bug
import astropy
In [3]: runfile('ap.py')
In [4]: runfile('ap.py')
Reloaded modules: astropy.utils, astropy.extern.configobj.configobj, astropy.config.affiliated, astropy, astropy.extern.plugins.pytest_remotedata, astropy.extern, astropy.utils.introspection, astropy.config, astropy.extern.six, astropy.extern.bundled, astropy.utils.decorators, astropy._compiler, astropy.extern.plugins, astropy.config.configuration, astropy.extern.configobj, astropy.extern.bundled.six, astropy.config.paths, astropy.extern.configobj.validate, astropy.utils._compiler, astropy.tests, astropy.cython_version, astropy.version, astropy.tests.runner, astropy.utils.misc, astropy.logger, astropy.utils.codegen, astropy.utils.exceptions, astropy.extern.plugins.pytest_remotedata.disable_internet
In [5]: runfile('ap.py')
Reloaded modules: astropy.utils, astropy.extern.configobj.configobj, astropy.config.affiliated, astropy, astropy.extern.plugins.pytest_remotedata, astropy.extern, astropy.utils.introspection, astropy.config, astropy.extern.six, astropy.extern.bundled, astropy.utils.decorators, astropy._compiler, astropy.extern.plugins, astropy.config.configuration, astropy.extern.configobj, astropy.extern.bundled.six, astropy.config.paths, astropy.extern.configobj.validate, astropy.utils._compiler, astropy.tests, astropy.cython_version, astropy.version, astropy.tests.runner, astropy.utils.misc, astropy.logger, astropy.utils.codegen, astropy.utils.exceptions, astropy.extern.plugins.pytest_remotedata.disable_internet
Traceback (most recent call last):
File "<ipython-input-5-9b9f963d0dcf>", line 1, in <module>
runfile('ap.py')
File "/usr/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "/usr/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)
File "ap.py", line 3, in <module>
import astropy
File "/data/derek/lib64/python2.7/site-packages/astropy/__init__.py", line 287, in <module>
log = _init_log()
File "/data/derek/lib64/python2.7/site-packages/astropy/logger.py", line 100, in _init_log
log._set_defaults()
File "/data/derek/lib64/python2.7/site-packages/astropy/logger.py", line 484, in _set_defaults
self.disable_warnings_logging()
File "/data/derek/lib64/python2.7/site-packages/astropy/logger.py", line 253, in disable_warnings_logging
if warnings.showwarning != self._showwarning:
AttributeError: 'NoneType' object has no attribute 'showwarning'
With slightly more complex scripts the error will be triggered already on the second runfile(). Adding astropy to the list of modules excluded from UMR in the preferences avoids the issue.
A bit more context for those with access can be found in the Python users in Astronomy Facebook group.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (21 by maintainers)
For example, a similar issue was reported here: https://github.com/EMS-TU-Ilmenau/fastmat/issues/27
Thank you for investigating! If you feel like this is useful to be documented under http://astropy.readthedocs.io/en/latest/known_issues.html , PR is welcome.
OK, I found that
Spyderjust did not reloadastropyon my Mac because it skips all modules installed under the system path. After disabling that, I could reproduce the crash under MacOS inPython 2.7.14forastropy 2.0.5. Whereas under both3.5.5and3.6.5theSpyderreload works forastropyversions from1.2.1to3.0.1. Makes it likely thatPython 3in general is indeed not affected by the bug - my guess is theimport _compilererror under Linux was rather caused by the library being compiled under an older OS version, although I don’t understand then why the import succeeded the first two times…@dhomeier yes of course, sorry I missed that. Regardless,
astropy-1.2.xis no longer being supported, so unless you can show that this happens with a more recent version of astropy in a Python3Spyderenvironment, I would still argue that no action needs to be taken.