简体   繁体   English

使用virtualenv安装某些软件包

[英]Installing certain packages using virtualenv

So, I want to start using virtualenv this year. 所以,我想今年开始使用virtualenv。 I like the no-site-packages option, that is nice. 我喜欢no-site-packages选项,这很好。 However I was wondering how to install certain packages into each virtualenv. 但是我想知道如何在每个virtualenv中安装某些软件包。 For example, lets say I want to install django into each virtualenv... is this possible, and if so, how? 例如,假设我想将django安装到每个virtualenv中...这是可能的,如果是这样,怎么样? Does buildout address this? buildout会解决这个问题吗?


Well it's not so much django, more like the django applications... I dont mind installing a version of django into each virtualenv... i was just wondering if there was some intermediate option to 'no-site-packages' 好吧,它不是django,更像是django应用程序...我不介意在每个virtualenv中安装一个版本的django ...我只是想知道是否有一些'no-site-packages'的中间选项

I know where you're coming from with the no-sites-option. 我知道你在哪里使用no-sites-option。 I want to use pip freeze to generate requirements lists and don't want a lot of extra cruft in site-packages. 我想使用pip freeze来生成需求列表,并且不希望在站点包中有很多额外的错误。 I also need to use multiple versions of django as I have legacy projects I haven't upgraded (some old svn checkouts (pre1.0), some 1.0, and some new svn checkouts). 我还需要使用多个版本的django,因为我有遗留项目我没有升级(一些旧的svn checkout(pre1.0),一些1.0,以及一些新的svn checkout)。 Installing Django in the global site-packages isn't really an option. 在全局站点包中安装Django并不是一个真正的选择。

Instead I have a django folder with releases and a couple of different svn versions and just symlink to the appropriate version in the local site-packages. 相反,我有一个带有发行版的django文件夹和几个不同的svn版本,只有符号链接到本地​​站点包中的相应版本。 For ease of use I link to the local site-packages at the same level as the environment and then link in the appropriate django directory and any other "system" style packages I need (usually just PIL). 为了便于使用,我链接到与环境相同级别的本地站点包,然后链接到相应的django目录和我需要的任何其他“系统”样式包(通常只是PIL)。 So: 所以:

$ virtualenv pyenv
$ ln -s ./pyenv/lib/python2.5/site-packages ./installed
$ ln -s /usr/lib/python2.5/site-packages/PIL ./installed
$ ln -s /opt/django/django1.0svn/trunk/django ./installed

Now the following works: 现在以下工作:

$ source pyenv/bin/activate
$ python
> import django
> import PIL

If you want django to be installed on EACH virtualenv, you might as well install it in the site-packages directory? 如果你想在每个virtualenv上安装django,你可以将它安装在site-packages目录中吗? Just a thought. 只是一个想法。

I'd suggest using virtualenv 's bootstrapping support. 我建议使用virtualenvbootstrapping支持。 This allows you to execute arbitrary Python after the virtualenv is created, such as installing new packages. 这允许您在创建virtualenv之后执行任意Python,例如安装新包。

The other option (one I've used) is to easy_install Django after you've created the virtual environment. 另一个选项(我使用的一个)是在创建虚拟环境后easy_install Django。 This is easily scripted. 这很容易编写脚本。 The penalty you pay is waiting for Django installation in each of your virtual environments. 您支付的罚款是等待在每个虚拟环境中安装Django。

I'm with Toby, though: Unless there's a compelling reason why you have to have a separate copy of Django in each virtual environment, you should just consider installing it in your main Python area, and allowing each virtual environment to use it from there. 我和Toby在一起:除非有一个令人信服的理由为什么你必须在每个虚拟环境中都有一个单独的Django副本,你应该考虑将它安装在主Python区域,并允许每个虚拟环境从那里使用它。

I want to check out this project: 我想查看这个项目:

http://www.stereoplex.com/two-voices/fez-djangoskel-django-projects-and-apps-as-eggs http://www.stereoplex.com/two-voices/fez-djangoskel-django-projects-and-apps-as-eggs

Might be my answer.... 可能是我的答案....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM