如何配置内部Python工具的Shebang线

How to configure Shebang line of internal Python Tools

我正在尝试构建一个最小的 docker 图像,除了 运行 Python 解释器之外别无他物。在开发过程中,我从 alpine 开始,最终图像将构建 FROM scratch。我正在 Linux Mint 机器上工作。

我能够编译 Python 编译器并将其安装到我当前的工作目录中,如下所示:

cd Python-3.8.7
./configure --prefix=$PWD/../python
make install

但是,我没有找到如何正确调整 --prefix 设置,以便创建的 shebang 稍后可以在 docker 容器中工作。

./python/pip3的第一行包含我的主机的绝对路径并读取

#!/home/orion/minimal_py_image/Python-3.8.7/../python/bin/python3.8

但它应该是

#!/python/bin/python3.8

因为 /python 是在 docker 图像中找到 Python 解释器的位置。

如何欺骗 make install 脚本,使最终目的地成为 /python/bin

我想将构建包含在当前目录中,即 而不是 使用我进行编译的主机上的文件夹 /python

附加信息

可能与这个问题没有直接关系,但作为参考:这是我试图开始工作的 Dockerfile:

FROM alpine

COPY python /python

COPY lib64/* /lib64/

ENV LD_LIBRARY_PATH=/usr/lib64/:/lib64/:/python/lib
ENV PATH="${PATH}:/python/bin"

我已经能够 运行 Python docker run -it mini python3 -c "print('hello from python')" 但是 pip 还没有工作,因为错误的 shebang。

基于 Autoconf 的构建系统中的一个常见约定是支持 Make 变量 DESTDIR。当你 运行 make install 时,如果设置了 DESTDIR,它实际上会安装到 DESTDIR 下配置的目录中,但仍然使用原始路径构建。然后您可以创建目标目录的存档,或者在 Docker 上下文中,将该目录用作构建上下文。

cd Python-3.8.7
# Use the final install target as the --prefix
./configure --prefix=/python
# Installs into e.g. ../python/python/bin/python3.8
make install DESTDIR=../python

cd ../python
tar cvzf ../python.tar.gz .

你可以在很多地方看到这个变量referenced in the Python Makefile