使用distutils在chroot环境中安装

2 投票
1 回答
913 浏览
提问于 2025-04-16 10:20

我在维护一个被限制在特定环境中的Linux镜像,我想把一个软件包安装到这个环境里。

但是这两个软件包都被安装到了两个地方,我搞不清楚发生了什么,也不知道该怎么解决。

这是我的setup.py文件:

import os
from distutils.core import setup

setup(name='ServerLibrary',
    version='1.1',
    description='Server Framework',
    author='Michael Brown',
    scripts = [ 'foo.py' ],
    packages = [ 'ServerLibrary' ],
)

os.chroot('/srv/nfs/chrooted-nfs-client/')
setup(name='ClientLibrary',
    version='1.1',
    description='Client Framework',
    author='Michael Brown',
    packages = [ 'ClientLibrary' ],
)

有什么好的方法可以实现我想做的事情吗?

1 个回答

1

我发现我需要为一组文件指定一个不同的构建目录。因为distutils默认认为每次都要安装'build'文件夹里的所有东西。

希望我能帮别人省去 figuring out 这个问题的麻烦。下面是我修正后的脚本第二部分:

os.chroot('/srv/nfs/chrooted-nfs-client/')
setup(name='ClientLibrary',
    version='1.1',
    description='Client Framework',
    author='Michael Brown',
    packages = [ 'ClientLibrary' ],
    options = {
        'build': { 'build_base': 'build-chroot' }
    }
)

撰写回答