Skip to content

AttributeError: module 'swisseph' has no attribute 'swe_julday' in Python 3.9 slim Docker images #84

@Shrinagara

Description

@Shrinagara

Hello,

I'm encountering a persistent AttributeError when trying to use certain functions from the pyswisseph module within Docker containers. This issue occurs even after attempting various solutions, and I would appreciate some guidance.

Problem Description:
When importing swisseph and trying to call functions like swe.swe_julday(), swe.swe_calc_ut(), or swe.swe_houses_ex(), I consistently receive an AttributeError, stating that the module has no such attribute.

Key Observation:
Curiously, if I inspect the swisseph module using dir(swe), these attributes (julday, calc_ut, houses_ex) do appear in the list of available attributes. However, attempting to call them results in the AttributeError. Other more general functions like swe.calc() and swe.houses() (without the swe_ prefix) do work as expected.

Environment Details:

Host OS: macOS Catalina (Intel, if applicable, though problem seems confined to Docker env)

Docker Desktop Version: 4.15.0

Docker Base Images Tested (in Dockerfile):

  • python:3.9-slim-buster (Debian 10)
  • python:3.9-slim-bullseye (Debian 11)
  • python:3.9-slim-jammy (Ubuntu 22.04 - Note: Tag was python:3.9-slim-ubuntu22.04 in Dockerfile, but still resulted in AttributeError on relevant functions after successful build)
  • python:3.9-slim
  • pyswisseph versions tested (in requirements.txt):
  • pyswisseph==2.10.3.2 (Latest stable)
  • pyswisseph==2.10.3.1
  • pyswisseph==2.08.00-1

Dockerfile.txt (latest version used, with python:3.9-slim-buster for example):

Dockerfile

FROM python:3.9-slim-buster

# Install necessary system dependencies for pyswisseph compilation
# (build-essential, libgfortran5, python3-dev, libatlas-base-dev)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    libgfortran5 \
    python3-dev \
    libatlas-base-dev \
    && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python3", "main.py"]

requirements.txt:

pyswisseph==2.10.3.2
tabulate
pytz

Relevant snippet from src/core/ephemeris_calculator.py that causes the error:

Python

import swisseph as swe
from datetime import datetime, timedelta

# ... (rest of the class definition) ...

    def calculate_planet_position_with_speed(self, planet_id, year, month, day, hour, minute, second, timezone_offset):
        utc_dt = self._convert_local_to_utc(year, month, day, hour, minute, second, timezone_offset)
        # This line causes the AttributeError:
        jd = swe.swe_julday(utc_dt.year, utc_dt.month, utc_dt.day,
                            utc_dt.hour + utc_dt.minute / 60.0 + utc_dt.second / 3600.0,
                            swe.SE_GREG_CAL)
        
        # This line also causes AttributeError:
        # xx, retflag = swe.swe_calc_ut(jd, planet_id, swe.SEFLG_SWIEPH | swe.SEFLG_SPEED)
        # (Using swe.calc() instead works)

        # This line also causes AttributeError:
        # retflag, cusps, ascmc = swe.swe_houses_ex(jd, latitude, longitude, b'W')
        # (Using swe.houses() instead works)

        # ... (rest of the function) ...

Steps to Reproduce:

  1. Save the Dockerfile.txt, requirements.txt, and the ephemeris_calculator.py snippet as described.

  2. Build the Docker image (ensure ephemeris_calculator.py is in its original state, calling swe.swe_julday etc.):
    docker build -t jyotish_app . -f Dockerfile.txt --no-cache

  3. Run the container:
    docker run jyotish_app

Expected Behavior:
The swe.swe_julday(), swe.swe_calc_ut(), and swe.swe_houses_ex() functions should execute without an AttributeError, as they are part of the documented pyswisseph API and appear in dir(swe).

Actual Behavior:
AttributeError: module 'swisseph' has no attribute 'swe_julday' (or swe_calc_ut, swe_houses_ex if called).

Any insights or suggestions on why these specific functions might not be binding correctly in these Docker environments, despite the attributes appearing in dir(), would be greatly appreciated. It seems related to the binary compilation or linking within minimal Linux environments.

Thank you for your time and assistance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions