Crash: AttributeError: partially initialized module 'redback' has no attribute 'utils'
Closed this issue · 4 comments
System: WSL2 + Archlinux
python version 3.11, virtual enviroment
installed with pip and requirments.txt also installed explicitly
Run in Jupyter notebook
import redback
results in error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[17], line 1
----> 1 import redback
File ~/pyvenvi/lib/python3.11/site-packages/redback/__init__.py:1
----> 1 from redback import constants, utils, analysis, get_data, redback_errors, priors, result, sampler, transient, \
2 transient_models, photosphere, sed, interaction_processes, constraints, plotting, model_library
3 from redback.transient import afterglow, kilonova, prompt, supernova, tde
4 from redback.sampler import fit_model
File ~/pyvenvi/lib/python3.11/site-packages/redback/analysis.py:8
6 import redback.model_library
7 from redback.utils import logger
----> 8 from redback.result import RedbackResult
11 def _setup_plotting_result(model, model_kwargs, parameters, transient):
12 """
13 Helper function to setup the plotting result
14
(...)
19 :return: a tuple of model, parameters, and result
20 """
File ~/pyvenvi/lib/python3.11/site-packages/redback/result.py:12
9 from bilby.core.result import Result
10 from bilby.core.result import _determine_file_name # noqa
---> 12 import redback.transient.transient
13 from redback import model_library
14 from redback.transient import TRANSIENT_DICT
File ~/pyvenvi/lib/python3.11/site-packages/redback/transient/__init__.py:1
----> 1 from redback.transient import afterglow, kilonova, prompt, supernova, tde, transient
2 from redback.transient.afterglow import Afterglow, LGRB, SGRB
3 from redback.transient.kilonova import Kilonova
File ~/pyvenvi/lib/python3.11/site-packages/redback/transient/afterglow.py:12
9 from astropy.cosmology import Planck18 as cosmo # noqa
11 from redback.get_data.directory import afterglow_directory_structure
---> 12 from redback.transient.transient import Transient
13 from redback.utils import logger
15 dirname = os.path.dirname(__file__)
File ~/pyvenvi/lib/python3.11/site-packages/redback/transient/transient.py:14
9 import redback
10 from redback.plotting import \
11 LuminosityPlotter, FluxDensityPlotter, IntegratedFluxPlotter, MagnitudePlotter, IntegratedFluxOpticalPlotter
---> 14 class Transient(object):
15 DATA_MODES = ['luminosity', 'flux', 'flux_density', 'magnitude', 'counts', 'ttes']
16 _ATTRIBUTE_NAME_DICT = dict(luminosity="Lum50", flux="flux", flux_density="flux_density",
17 counts="counts", magnitude="magnitude")
File ~/pyvenvi/lib/python3.11/site-packages/redback/transient/transient.py:25, in Transient()
16 _ATTRIBUTE_NAME_DICT = dict(luminosity="Lum50", flux="flux", flux_density="flux_density",
17 counts="counts", magnitude="magnitude")
19 ylabel_dict = dict(luminosity=r'Luminosity [$10^{50}$ erg s$^{-1}$]',
20 magnitude=r'Magnitude',
21 flux=r'Flux [erg cm$^{-2}$ s$^{-1}$]',
22 flux_density=r'Flux density [mJy]',
23 counts=r'Counts')
---> 25 luminosity_data = redback.utils.DataModeSwitch('luminosity')
26 flux_data = redback.utils.DataModeSwitch('flux')
27 flux_density_data = redback.utils.DataModeSwitch('flux_density')
AttributeError: partially initialized module 'redback' has no attribute 'utils' (most likely due to a circular import)
Hi @opyshna - I have not tested redback on 3.11 before. The CI are passing on 3.9/3.10 right now. If its easy can you check those versions while I look into this?
Also - can you try running one of the examples? The circular import error can occur if you have a clash in the name of a file and the name of the module you are wanting to import e.g., here https://stackoverflow.com/questions/71022019/attributeerror-partially-initialized-module-x-has-no-attribute-y-most-likely-d
So just to ensure its not that - you do not have any files called redback right?
I've just tried installing on a fresh conda environment with python3.11 on mac os and I cannot reproduce this error.
Thank you, I did not use conda, and the issue dissappeared after I restarted a jupyter notebook several times and it does not appear in other jupyter notebooks as well
Great - I'll close this issue then.