slimtoolkit / slimtoolkit/slim
python module not found errors
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 23.4k
- Forks
- 841
- PR merge metrics
- No merged PRs in 30d
Description
Facing Modules / package error
2023-07-12 17:08:15 Traceback (most recent call last):
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/decimal.py", line 3, in
2023-07-12 17:08:15 from _decimal import *
2023-07-12 17:08:15 ModuleNotFoundError: No module named 'numbers'
2023-07-12 17:08:15
2023-07-12 17:08:15 During handling of the above exception, another exception occurred:
2023-07-12 17:08:15
2023-07-12 17:08:15 Traceback (most recent call last):
2023-07-12 17:08:15 File "main.py", line 2, in
2023-07-12 17:08:15 from fastapi import FastAPI
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/site-packages/fastapi/init.py", line 7, in
2023-07-12 17:08:15 from .applications import FastAPI as FastAPI
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 3, in
2023-07-12 17:08:15 from fastapi import routing
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 20, in
2023-07-12 17:08:15 from fastapi import params
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/site-packages/fastapi/params.py", line 4, in
2023-07-12 17:08:15 from pydantic.fields import FieldInfo, Undefined
2023-07-12 17:08:15 File "pydantic/init.py", line 2, in init pydantic.init
2023-07-12 17:08:15 File "pydantic/dataclasses.py", line 3, in init pydantic.dataclasses
2023-07-12 17:08:15 import copy
2023-07-12 17:08:15 File "pydantic/class_validators.py", line 8, in init pydantic.class_validators
2023-07-12 17:08:15 File "pydantic/errors.py", line 1, in init pydantic.errors
2023-07-12 17:08:15 File "/usr/local/lib/python3.8/decimal.py", line 8, in
2023-07-12 17:08:15 from _pydecimal import *
2023-07-12 17:08:15 ModuleNotFoundError: No module named '_pydecimal'
Steps to Reproduce the Problem (DockerFile)
FROM python:3.8-slim-buster AS build
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y --no-install-recommends
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt
Stage 2: Final stage
FROM python:3.8-slim-buster
WORKDIR /app
COPY --from=build /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
COPY . .
RUN pip install --no-cache-dir -r requirements.txt fastapi==0.68.1 uvicorn==0.15.0
CMD ["bash", "azure-soc2-manager.sh"]
EXPOSE 8000
Create preserved-paths.txt file in the final image
RUN echo "/usr/local/usr/local/lib/python3.8" > /preserved-paths.txt
- first i build the image using the above docker file
- Then i slim the image build
command use are
docker build -t soc2-test-1 . (to build-image)
docker-slim build --target soc2-test-11 --tag soc2-test-slim --http-probe=false
docker images | grep soc2
soc2-test-1 slim
cf086482e0b3 About a minute ago 33.9MB
soc2-test-1 latest
d3fdfab4467d 10 minutes ago 279MB
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Dockerfile, requirements.txt, and the docker-slim build command, then reproduce the missing numbers and _pydecimal errors in the slim image. Compare the build and final stages, including the preserved-paths.txt entry, and determine which Python modules are removed; done means the slimmed FastAPI image starts without these import failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, fastapi, python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100