Reputation: 10609
I have the following dockerfile:
FROM python:alpine3.6
ENV PORT 5000
ENV APP /usr/src
ENV FLASK_APP pkg_name/app.py
RUN apk update
RUN apk upgrade
RUN apk add build-base postgresql-dev git gcc
RUN apk add musl-dev python3-dev libffi-dev
ADD . /
RUN python setup.py install
# RUN pip install .
EXPOSE $PORT
CMD flask run
the configuration above work perfectly in standard python image but not in alpine image. Both python setup.py install
or pip install .
will install the package correctly but when I run flask run
it complain that the installed module is not found:
Traceback (most recent call last):
File "pkg_name/app.py", line 6, in <module>
from pkg_name.api import api
ModuleNotFoundError: No module named 'pkg_name'
Running pip freeze
shows that the project in the list of installed packages. Trying to import the project in the python interpreter >>> import pkg_name
works also fine, which is weird.
Question:
Does any one has an explanation why the pkg could not be imported on run time despite it's installed and imported correctly in the interpeter. How can I fix it.
Upvotes: 4
Views: 3013
Reputation: 10609
A solution that worked for me was setting the PYTHONPATH
variable.
PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3.6/site-packages
Still feel is just a dirty workaround, because the site-packages path is in the sys.path
and the packages are correctly installed there, but for now it solved the issue.
Upvotes: 2