虚拟环境蛋黄问题 [英] virtualenv yolk problem

查看:99
本文介绍了虚拟环境蛋黄问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

yolk -l给我的信息是我在Ubuntu 10.04上安装了114个软件包.使用

yolk -l gives me information that I've got 114 packages installed on my Ubuntu 10.04. After creating new virtualenv directory using

virtualenv virt_env/virt1 --no-site-packages --clear

我切换到该位置,提示符更改了,然后yolk -l再次给了我同样的114个程序包.

I switched to that, my prompt changed and then yolk -l gives me again the same 114 packages.

那里发生了什么事?

推荐答案

通过更改Shell PATH来激活virtualenv,因此将virtualenv的bin/目录放在首位.这就是所有.这意味着,当您运行"python"时,它将运行virtualenv的Python二进制副本,而不是全局系统python.

Activating a virtualenv works by changing your shell PATH so the virtualenv's bin/ directory is first. This is all it does. This means that when you run "python" it runs the virtualenv's copy of the Python binary instead of your global system python.

但是,如果您在全球范围内安装了蛋黄,那么PATH上唯一的蛋黄"二进制文件是/usr/local/bin/yolk或类似的文件;激活virtualenv不会更改此操作(因为您的virtualenv bin/目录中没有卵黄"脚本).并且/usr/local/bin/yolk脚本自然会在其shebang行中包含您的系统Python解释器.

If you have yolk installed globally, however, the only "yolk" binary on your PATH is /usr/local/bin/yolk or some such; activating the virtualenv doesn't change this (because there's no "yolk" script in your virtualenv bin/ dir). And the /usr/local/bin/yolk script naturally has your system Python interpreter in its shebang line.

这就是为什么将蛋黄安装到virtualenv中可以解决此问题的原因;因为它在您的virtualenv bin/目录中添加了一个卵黄脚本,在shebang行中包含了virtualenv的python.

This is why installing yolk into the virtualenv fixes the problem; because it adds a yolk script in your virtualenv bin/ dir that has the virtualenv's python in its shebang line.

如果您不想在每个virtualenv中安装卵黄质,也可以从/usr/local/bin或任何地方将卵黄质脚本包装程序复制到virtualenv的bin目录中,然后手动将shebang行更改为指向您的virtualenv的python.但是,这不适用于--no-site-packages virtualenv,因为脚本包装器将无法找到它需要导入的实际蛋黄包!如果要在--no-site-packages virtualenv中使用卵黄质,那么实际上唯一的选择就是将卵黄质安装在其中.

If you don't want to install yolk in each virtualenv, you could also just copy the yolk script-wrapper from /usr/local/bin or wherever it is into your virtualenv's bin dir, and manually change the shebang line to point to your virtualenv's python. This won't work with a --no-site-packages virtualenv, though, because the script wrapper then won't be able to find the actual yolk packages it needs to import! If you want to use yolk within a --no-site-packages virtualenv, really your only choice is to install it there.

这篇关于虚拟环境蛋黄问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆