问题描述
我正在使用 buildout 和 virtualenv 的组合在 python 中设置一个隔离开发环境,允许进行可重复的构建.
I am messing around with the combination of buildout and virtualenv to setup an isolated development environment in python that allows to do reproducible builds.
有一个构建方法可以让您将 virtualenv 集成到构建中:
There is a recipe for buildout that let's you integrate virtualenv into buildout:
tl.buildout_virtual_python
有了这个,我的 buildout.cfg 看起来像这样:
With this my buildout.cfg looks like this:
[buildout]
develop = .
parts = script
virtualpython
[virtualpython]
recipe = tl.buildout_virtual_python
headers = true
executable-name = vp
site-packages = false
[script]
recipe = zc.recipe.egg:scripts
eggs = foo
python = virtualpython
这会将两个可执行文件部署到 ./bin/中:
This will deploy two executables into ./bin/:
vp
script
当我执行 vp 时,我得到了一个交互式的、独立的 python 对话框,正如预期的那样(无法从系统加载任何包).我现在期望的是,如果我运行
When I execute vp, I get an interactive, isolated python dialog, as expected (can't load any packages from the system).What I would expect now, is that if I run
./bin/script
使用了隔离的python解释器.但事实并非如此,它并没有像vp"那样孤立(这意味着我可以从系统级别导入库).但是我可以运行:
that the isolated python interpreter is used. But it doesn't, it's not isolated as "vp" is (meaning I can import libraries from system level). However I can run:
./bin/vp ./bin/script
这将按照我的意愿在隔离的环境中运行脚本.但是必须有一种方法可以在不链接命令的情况下指定这样做,否则 buildout 只能解决我希望的一半问题:)
Which will run the script in an isolated environment as I wished. But there must be a way to specify this to do so without chaining commands otherwise buildout only solves half of the problems I hoped :)
感谢您的帮助!帕特里克
Thanks for your help!Patrick
推荐答案
你不需要 virtualenv:buildout 已经提供了一个隔离的环境,就像 virtualenv 一样.
You don't need virtualenv: buildout already provides an isolated environment, just like virtualenv.
举个例子,看看 buildout 在 bin 目录中生成的文件.他们会有类似的东西:
As an example, look at files buildout generates in the bin directory. They'll have something like:
import sys
sys.path[0:0] = [
'/some/thing1.egg',
# and other things
]
因此 sys.path
被完全替换为构建想要在路径上拥有的内容:与 virtualenv 相同的隔离方法.
So the sys.path
gets completely replaced with what buildout wants to have on the path: the same isolation method as virtualenv.
这篇关于构建和 Virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!