【问题标题】:python-3.7 build from source, pip not being installed in altroot/DESTDIRpython-3.7 从源代码构建,pip 未安装在 altroot/DESTDIR 中
【发布时间】:2019-03-20 14:23:38
【问题描述】:

我有一个自定义的 linux 发行版,并且正在从源代码构建 python 3.7.2。该构建被配置为安装到备用根目录中,它将被打包以进行安装。

当在尚未安装 python3 的系统上运行时,此过程可以正常工作。但是,当我在具有先前构建的相同软件包副本的主机上运行相同的构建过程时,ensurepip 无法将 pip 或 setuptools 安装到备用安装目录中,因为它会在系统本身上找到它们。

软件提取和配置调用如下:

mkdir -p /data/buildspace/work/python3-x86_64
/bin/tar xf /data/sources/python3/Python-3.7.2.tgz \
     -C /data/buildspace/work/python3-x86_64
( cd /data/buildspace/work/python3-x86_64/Python-3.7.2 ; \
     [ -f ./configure ] && CC="gcc" CXX="g++" ./configure \
     --prefix=/usr --libdir=/usr/lib
     --sysconfdir=/etc --bindir=/usr/bin  || echo "No './configure' script")

然后调用make install 并指定DESTDIR:

make -C /data/buildspace/work/python3-x86_64/Python-3.7.2
    install DESTDIR=/data/buildspace/work/python3-x86_64/root 

最初构建时,在构建系统安装 python3 之前,我在构建输出/日志中看到:

if test "xupgrade" != "xno"  ; then \
    case upgrade in \
            upgrade) ensurepip="--upgrade" ;; \
            install|*) ensurepip="" ;; \
    esac; \
     ./python -E -m ensurepip \
            $ensurepip --root=/data/buildspace/work/python3-x86_64/root/ ; \
fi
Looking in links: /tmp/tmpa9_lumsc
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

但是,在安装了 python3 的系统上构建时,我找不到任何方法来阻止它考虑 /usr/lib/python3.7/site-packages 中的 pip。运行相同的配置将产生:

Looking in links: /tmp/tmp086yebrw
Requirement already up-to-date: setuptools in /usr/lib/python3.7/site-packages (40.6.2)
Requirement already up-to-date: pip in /usr/lib/python3.7/site-packages (18.1)

然后,我尝试了--with-ensurepip=install,但这只是稍微改变了输出:

Looking in links: /tmp/tmpl0x88vr9
Requirement already satisfied: setuptools in /usr/lib/python3.7/site-packages (40.6.2)
Requirement already satisfied: pip in /usr/lib/python3.7/site-packages (18.1)

我不知道这是否是 ensurepip 中的一个错误,在指定 --root 运行时它不应该考虑默认的 python 库目录,或者我是否缺少这个“安装到一个整体”的东西新空间”。

我查看了使用venv的想法,但是我希望生成的二进制文件能够在打包和安装后在系统上的正常位置运行,所以我认为这可能是错误的方向.

欣赏任何指针。谢谢。

【问题讨论】:

  • 你是怎么解决的?
  • 这里也有兴趣
  • 我也有同样的情况。我已经安装了另一个版本的 python。当我从源代码构建 Python 的第二个版本时,ensurepip 发现我在第一个版本的其他地方有 pip,因此不会安装它。结果是第二个版本中缺少 pip 并且我使用的脚本取决于它是否存在于第二个版本中失败。引用原始版本的 pip 并不能解决问题。

标签: python python-3.x pip


【解决方案1】:

三年后,没有提供答案,this bug has existed within ensurepip since 2015,所以为了后代,我想我会分享对我有用的解决方案:

改用get-pip,并在调用get-pip.py 时传递--ignore-installed 标志,以防止覆盖预先存在的系统安装pip。

$ cd <python_bin_dir>
$ curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --ignore-installed

【讨论】:

    猜你喜欢
    • 2022-11-15
    • 2015-08-19
    • 2021-12-16
    • 1970-01-01
    • 2018-10-09
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多