如何配置内部Python工具的Shebang行 [英] How to configure Shebang line of internal Python Tools
问题描述
我正在尝试构建一个最小的docker映像,仅能运行Python解释器而已.在开发过程中,我从高山开始,最终图像将构建为 FROM scratch
.我正在Linux Mint机器上工作.
I am trying to build a minimal docker image, capable of nothing more but running the Python interpreter. During development I start from alpine, the final image will be build FROM scratch
. I am working on a Linux Mint machine.
我能够编译Python编译器,并将其安装到我当前的工作目录中,如下所示:
I am able to compile the Python compiler and install it into my current working directory like this:
cd Python-3.8.7
./configure --prefix=$PWD/../python
make install
但是,我没有找到如何正确调整-prefix
设置的方法,以使创建的shebang稍后可在docker容器中工作.
However, I did not find out how to tweak the --prefix
settings correctly so that the created shebangs will later work in the docker container.
./python/pip3
的第一行包含主机的绝对路径并读取
First line of ./python/pip3
contains the absolute path of my host and reads
#!/home/orion/minimal_py_image/Python-3.8.7/../python/bin/python3.8
但它应该读
#!/python/bin/python3.8
因为/python
是在Docker映像中找到Python解释器的位置.
because /python
is the location under which the Python interpreter will be found in the docker image.
如何欺骗 make install
脚本,以使最终目的地为/python/bin
?
How can I trick the make install
script so that the final destination will be /python/bin
?
我想使用我进行编译的主机上的文件夹/python
将构建保留在当前目录中,即 not .
I would like to keep the build contained in the current directory i.e. not using the folder /python
on the host where I do the compilation.
其他信息
可能与该问题没有直接关系,但作为参考:这是我正在尝试使用的Dockerfile:
Probably not directly relevant for this question but as reference: Here is the Dockerfile I am trying to get working:
FROM alpine
COPY python /python
COPY lib64/* /lib64/
ENV LD_LIBRARY_PATH=/usr/lib64/:/lib64/:/python/lib
ENV PATH="${PATH}:/python/bin"
我已经能够使用 docker run -it mini python3 -c"print('hello from python')'
推荐答案
基于Autoconf的构建系统中的常见约定是支持Make变量 DESTDIR
.运行 make install
时,如果设置了 DESTDIR
,它实际上将安装到 DESTDIR
下的已配置目录中,但仍使用原始路径进行构建.然后,您可以创建目标目录的存档,或者在Docker上下文中,将该目录用作构建上下文.
A common convention in Autoconf-based build systems is to support a Make variable DESTDIR
. When you run make install
, if DESTDIR
is set, it actually installs into the configured directory under DESTDIR
, but still built with the original path. You can then create an archive of the target directory, or in a Docker context, use that directory as the build context.
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 .
您可以看到此变量在Python Makefile中引用的在很多地方.
You can see this variable referenced in the Python Makefile in many places.
这篇关于如何配置内部Python工具的Shebang行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!