title: Build Python and Pip from source and "bad interpreter: No such file or directory"
body: <p>I am trying to build <code>Python</code> and <code>Pip</code> from source. Following is the Dockerfile for it:</p>
  <pre><code>FROM buildpack-deps:stretch
  ARG PYTHON_VERSION=&quot;3.6.5&quot;
  ARG PIP_VERSION=&quot;20.2&quot;
  ARG INSTALLATION_PREFIX=&quot;/opt/python/${PYTHON_VERSION}&quot;
  
  WORKDIR /usr/src/python
  RUN wget -q https://www.python.org/ftp/python/$PYTHON_VERSION/Python-${PYTHON_VERSION}.tgz \
      &amp;&amp; apt-get update \
      &amp;&amp; apt-get install -y \
          make \
          build-essential \
          libssl-dev \
          zlib1g-dev \
          libbz2-dev \
          libreadline-dev \
          libsqlite3-dev \
          wget \
          curl \
          llvm \
          libncurses5-dev \
          libncursesw5-dev \
          xz-utils \
          tk-dev
  
  RUN tar xvf Python-${PYTHON_VERSION}.tgz \
      &amp;&amp; rm -f Python-${PYTHON_VERSION}.tgz
      
  RUN cd Python-$PYTHON_VERSION \
      &amp;&amp; ./configure \
          --prefix=${INSTALLATION_PREFIX} \
          --build=$(dpkg-architecture --query DEB_BUILD_GNU_TYPE) \
          --enable-loadable-sqlite-extensions \
          --enable-shared \
          --with-system-expat \
          --with-system-ffi \
          --without-ensurepip \
      &amp;&amp; make -j $(nproc) \
      &amp;&amp; make altinstall
  
  ENV LD_LIBRARY_PATH=&quot;${INSTALLATION_PREFIX}/lib:$LD_LIBRARY_PATH&quot;
  RUN wget -q https://bootstrap.pypa.io/get-pip.py -O /get-pip.py \
      &amp;&amp; /usr/src/python/Python-3.6.5/python /get-pip.py \
      --prefix ${INSTALLATION_PREFIX} \
      --disable-pip-version-check \
      --no-cache-dir \
      --no-warn-script-location \
      pip==${PIP_VERSION}
  
  WORKDIR /
  
  RUN mv ${INSTALLATION_PREFIX} /tmp/test
  ENV LD_LIBRARY_PATH=&quot;/tmp/test/lib:$LD_LIBRARY_PATH&quot;
  ENV PATH=&quot;/tmp/test/bin:$PATH&quot;
  </code></pre>
  <p>When I build the above Dockerfile, it builds fine and I am able to do <code>python3.6 --version</code> and <code>pip --version</code> and I get the expected results.</p>
  <p>Now because of a requirement that I have(Imagine building different Python versions from source in a docker image and store these built runtimes somewhere and install them on demand to a location before using it), I need to move this built Python and Pip to a different location, for example <code>/tmp/test</code>...I was hoping that Python and Pip executables would work just as before but when I do a <code>pip --version</code> I get the following error:</p>
  <pre><code>root@12c243458190:/# pip --version
  bash: /tmp/test/bin/pip: /opt/python/3.6.5/bin/python3.6: bad interpreter: No such file or directory
  </code></pre>
  <p><code>pip</code> seems to have hard-coded the location of <code>Python</code> to the installation prefix it was given when it was built.</p>
  <p>Any ideas on how to fix this issue?</p>