{"record":{"id":"48628c07ef2d2a4e","repo":"celery/celery","slug":"you-need-to-install-the-ephem-library-to-use-solar","errorCode":null,"errorMessage":"You need to install the ephem library to use solar schedules.\nPlease install by:\n\n    $ pip install celery[solar]\n","messagePattern":"You need to install the ephem library to use solar schedules\\.\nPlease install by:\n\n    \\$ pip install celery\\[solar\\]\n","errorType":"exception","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"error","filePath":"celery/schedules.py","lineNumber":805,"sourceCode":"    }\n    _use_center_l = {\n        'dawn_astronomical': True,\n        'dawn_nautical': True,\n        'dawn_civil': True,\n        'sunrise': False,\n        'solar_noon': False,\n        'sunset': False,\n        'dusk_civil': True,\n        'dusk_nautical': True,\n        'dusk_astronomical': True,\n    }\n\n    def __init__(self, event: str, lat: int | float, lon: int | float, **\n                 kwargs: Any) -> None:\n        try:\n            self.ephem = __import__('ephem')\n        except ImportError as exc:\n            raise ImproperlyConfigured(SOLAR_EPHEM_NOT_INSTALLED) from exc\n        self.event = event\n        self.lat = lat\n        self.lon = lon\n        super().__init__(**kwargs)\n\n        if event not in self._all_events:\n            raise ValueError(SOLAR_INVALID_EVENT.format(\n                event=event, all_events=', '.join(sorted(self._all_events)),\n            ))\n        if lat < -90 or lat > 90:\n            raise ValueError(SOLAR_INVALID_LATITUDE.format(lat=lat))\n        if lon < -180 or lon > 180:\n            raise ValueError(SOLAR_INVALID_LONGITUDE.format(lon=lon))\n\n        cal = self.ephem.Observer()\n        cal.lat = str(lat)\n        cal.lon = str(lon)\n        cal.elev = 0","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/celery/celery/blob/3511be41dbeca8f3c207c997ed9496a656b2a610/celery/schedules.py#L787-L823","documentation":"ImproperlyConfigured raised in solar.__init__ (schedules.py:805) when the 'ephem' astronomy library cannot be imported. celery's solar schedule depends on ephem to compute sunrise/sunset/transit times for a given latitude/longitude and event.","triggerScenarios":"Instantiating solar(event, lat, lon) without the ephem package installed in the environment. The __import__('ephem') at line 803 raises ImportError, which celery re-raises as ImproperlyConfigured with this message.","commonSituations":"Fresh deployment missing the solar extra; Docker/CI image that only installed base celery; upgrading celery and forgetting the optional dependency; conda vs pip environment mismatch.","solutions":["Install the solar extra: pip install celery[solar] (or pip install ephem directly).","Pin ephem in requirements.txt / pyproject to avoid surprise removals.","Rebuild Docker/CI images to include the extra after adding it.","If you do not actually need solar schedules, remove the solar(...) usage to drop the dependency."],"exampleFix":"# before (env missing ephem)\nfrom celery.schedules import solar\nbeat_schedule={'sun': {'task':'t', 'schedule': solar('sunrise', 40, -3)}}\n# after\n# shell:\n#   pip install celery[solar]\n# then the same Python code works unchanged","handlingStrategy":"validation","validationCode":"def require_solar_extra():\n    try:\n        import ephem  # noqa\n    except ImportError as e:\n        raise RuntimeError('Install celery[solar] (ephem) before using solar schedules') from e\n\nrequire_solar_extra()\nfrom celery.schedules import solar","typeGuard":"def solar_available() -> bool:\n    try:\n        import ephem  # noqa\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    from celery.schedules import solar\n    schedule = solar('sunrise', lat, lon)\nexcept Exception as e:  # ImproperlyConfigured\n    log.warning('solar unavailable, skipping: %s', e)\n    schedule = None","preventionTips":["Pin ephem in your dependency manifest.","Add a startup dependency check before registering solar schedules.","Document the solar extra in deployment runbooks."],"tags":["celery","scheduling","solar","dependency","configuration"],"backgroundTag":null,"analyzedSha":"3511be41dbeca8f3c207c997ed9496a656b2a610","analyzedAt":"2026-08-09T16:31:06.077Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}