pyinstaller是否具有gcc -static之类的参数? [英] Does pyinstaller have any parameters like gcc -static?

查看:149
本文介绍了pyinstaller是否具有gcc -static之类的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此有类似的问题:


尝试通过代码运行 docker运行测试,成功:



PS:


通过我的测试



  • CMD 必须用['xxx']而不是直接xxx来写。



  • / tmp 目录。



  • 其他python应用程序未测试,请关闭有关print的演示代码




I have a similar question to this : Is there a way to compile a Python program to binary and use it with a Scratch Dockerfile?

In this page, I saw that someone said that a C application runs well when compiled with -static.

So I have a new question: does pyinstaller have any parameters like gcc -static to make a python application run well in a Scratch Docker image?

解决方案

From the question Docker Minimal Image PyInstaller Binary File?'s commands,I get the links about how to make python binary to static,which like the go application demo,say hello world in scratch.

And I do a single ,easy demo,app.py:

print("test")

Then,do docker build with the Dockerfile:

FROM bigpangl/python:3.6-slim AS complier
WORKDIR /app
COPY app.py ./app.py

RUN apt-get update \
    && apt-get install -y build-essential patchelf \
    && pip install staticx pyinstaller \ 
    && pyinstaller -F app.py \
    && staticx /app/dist/app  /tu2k1ed

FROM scratch
WORKDIR /
COPY --from=complier /tu2k1ed /
COPY --from=complier /tmp /tmp
CMD ["/tu2k1ed"]

Get the image below, just 7.22M(I am not sure if could see the pic):

Try to run by code docker run test,successfully:

PS:

With my tests

  • the CMD must write by ['xxx'] not xxx direct.

  • /tmp directory is required in the demo.

  • other python application not test ,jsut the demo codes about print

这篇关于pyinstaller是否具有gcc -static之类的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆