Docker在Dockerfile中编译python文件不创建py

2024-04-19 10:44:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我会在Dockerfile中编译python文件(.py)以创建pyc文件,然后删除所有*.py。在

我创建了一个类似tisone的Dockerfile:

FROM python:3.6-alpine
EXPOSE 8000
RUN apk update
RUN apk add --no-cache make linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk add postgresql-dev gcc python3-dev musl-dev

VOLUME /var/lib/cathstudio/data
WORKDIR /var/lib/cathstudio/data

COPY ./requirements.txt .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1
#ENV PYTHONPATH /var/lib/cathstudio/data

COPY . /var/lib/cathstudio/data

RUN python -m compileall ajaxfuncs/

好吧,当我建立我的形象汇编似乎完成了:

enter image description here

但是当我浏览卷中的文件时,没有pyc文件:

enter image description here

如何在docker构建期间编译python文件以获得pycs?在

提前感谢你


Tags: pip文件runpydevdockerfileadddata
1条回答
网友
1楼 · 发布于 2024-04-19 10:44:12

它们已编译,您将在__pycache__文件夹中找到已编译的文件。如果您希望文件与原始文件位于同一目录中,则需要使用:compileall -b

Docs

-b

Write the byte-code files to their legacy locations and names, which may overwrite > byte-code files created by another version of Python. The default is to write files to > their PEP 3147 locations and names, which allows byte-code files from multiple > versions of Python to coexist.

相关问题 更多 >