如何确保buildout不使用已经安装的包?

2024-04-26 07:58:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试完全切换到buildout,但是我们的开发环境已经在/usr/lib/pythonxx/中安装了很多东西

如何确保buildout不会使用已经安装在系统上的库—最终没有virtualenv?在

例如-如何避免这种行为?公司名称:

> cat buildout.cfg
[buildout]
parts = django

[django]
recipe = zc.recipe.egg
eggs = django
interpreter = django

>bin/django 

>>> import django
>>> django
<module 'django' from '/usr/lib/python2.6/site-packages/django/__init__.pyc'>
>>> 

有没有强制buildout不使用/usr/lib/python2.6中安装的鸡蛋?在


Tags: django名称环境virtualenvlibusr系统buildout
3条回答

在构建1.5之前,我曾经使用过一种替代方法,它附带了从系统python中排除eggs的选项

虚拟人

我们编写了一个virtualenv自定义引导程序来创建环境fetch引导.py把最小的构建.cfg,但您可以正常使用virtualenv:

cd project virtualenv  no-site-packages ./
wget http://...../bootstrap.py 
touch buildout.cfg
source bin/activate
python bootstrap.py
bin/buildout

瞧,你的建筑被虚拟机隔离了

两种方式:

  • 使用最新的1.5.something构建:默认情况下,它们不使用系统包。

  • 运行带有-s标志的bootstrap命令:python bootstrap.py -s,这意味着“没有站点包”。

您可以告诉buildout是否要将站点包与以下两个指令之一一起使用:include-site-packages和{}

从buildoutdocumentation

You can then use include-site-packages = false and exec-sitecustomize = false buildout options to eliminate access to your Python's site packages and not execute its sitecustomize file, if it exists, respectively.

Alternately, you can use the allowed-eggs-from-site-packages buildout option as a glob-aware whitelist of eggs that may come from site-packages. This value defaults to "*", accepting all eggs.

相关问题 更多 >