web2py / py4web

Other
244 stars 126 forks source link

Dealing with PEP 668 and Docker #866

Closed Eddiedigits closed 3 months ago

Eddiedigits commented 4 months ago

Trying to install py4web via pip now gives an Externally Managed error. https://peps.python.org/pep-0668/

It is not possible to install py4web via: apt install python3-py4web plus using a requirements.txt is also difficult.

In this situation it is recommended to use venv. This can be an issue with Docker using an Ubuntu image as it uses sh which can't run the command source venv/bin/activate to activate the venv. Note: It is possible to activate the venv with a .sh script which runs in bash.

The solution I found is not to activate the venv in the usual way but to run pip via: venv/bin/pip. To run python use venv/bin/python Install only py4web: venv/bin/pip install py4web Py4web setup: venv/bin/py4web setup -Y apps Install requirements.txt: venv/bin/pip install -r requirements.txt

Start py4web: venv/bin/py4web run apps

FROM ubuntu:latest

ARG user=py4web

RUN apt update && \
    apt install -y git python3 python3-pip python3-venv memcached && \
    service memcached restart && \
    groupadd -r $user && \
    useradd -m -r -g $user $user

# check that the file has read access. If not, change the permissions
COPY password.txt /home/$user/password.txt
# RUN chmod a+r password.txt

USER $user

WORKDIR /home/$user/

RUN python3 -m venv venv && \
    venv/bin/pip install py4web && \
    venv/bin/py4web setup --yes apps

# or
# COPY requirements.txt /home/$user/requirements.txt
# RUN python3 -m venv venv && venv/bin/pip install -r requirements.txt

EXPOSE 8000

CMD py4web run --password_file password.txt --host 0.0.0.0 --port 8000 apps
mdipierro commented 3 months ago

There is no need to run venv in docker. Adds complexity an nothing else.