如何检查virtualenv是否使用'--no-site-packages'创建? [英] How to check whether virtualenv was created with '--no-site-packages'?

查看:3505
本文介绍了如何检查virtualenv是否使用'--no-site-packages'创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候我会收到错误,我怀疑是我的Django应用程序的结果,使用全球安装的Python模块/ Django应用程序,而不是其virtualenv中的那些。

Sometimes I get errors that I suspect are the result of my Django app using globally installed Python modules/Django apps instead of those within its virtualenv.

有没有方法来检查我的应用程序的virtualenv是否使用'--no-site-packages'创建,而无需删除它,然后重新创建它如下?

Is there a way to check whether my app's virtualenv was created with '--no-site-packages' without having to delete it, then re-create it as follows?

deactivate
rmvirtualenv my_env
mkvirtualenv my_env --no-site-packages
workon my_env
pip install -r requirements.txt

当然必须有更好的方法!谢谢。

Surely there must be a better way! Thanks.

推荐答案

< env> /lib/pythonX.X / code>当您使用创建虚拟环境时,调用 no-global-site-packages.txt - no-site-packages

There's a file in <env>/lib/pythonX.X/ called no-global-site-packages.txt when you create a virtual environment with --no-site-packages.

只需使用virtualenv 1.7:

Just tried this with virtualenv 1.7:

% virtualenv --no-site-packages env.without
% virtualenv --system-site-packages env.with

% find env.without | sed 's/env.without//' > files.without
% find env.with | sed 's/env.with//' > files.with

% diff files.with*
230a231
> /lib/python3.2/no-global-site-packages.txt

这篇关于如何检查virtualenv是否使用'--no-site-packages'创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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