9

当前的 Python 工作流程

我将pipDistributevirtualenvvirtualenvwrapper安装到我的 Python 2.7 站点包(Mac OS X 上安装的 Python 框架)中。在我~/.bash_profile的行中

export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache

这给出了如下工作流程:

$ mkvirtualenv pip-test
$ pip install nose        # downloaded and installed from PyPi
$ pip install mock        # downloaded and installed from PyPi
$ mkvirtualenv pip-test2
$ pip install nose        # installed from pip's download cache
$ pip install mock        # installed from pip's download cache

问题

由于我没有下载以前安装在另一个 virtualenv 中的软件包,因此此工作流程可以节省时间和带宽。但是,它不会节省磁盘空间,因为每个包都将安装到每个 virtualenv 中。因此,我想知道:

  • 问题 #1是否对此工作流程进行了修改,允许我通过让多个 virtualenvs 引用一个安装在我的 Python 2.7 站点包中的 Python 包来节省磁盘空间?

我试过使用add2virtualenv,它是 virtualenvwrapper 的一部分。虽然这“将指定的目录添加到当前活动的 virtualenv 的 Python 路径中”,但它不会添加在virtualenv/bin目录中找到的任何可执行文件。因此,以下将失败:

$ mkvirtualenv pip-test3
$ add2virtualenv ~/.virtualenvs/pip-test/lib/python2.7/site-packages/nose/
$ nosetests   # Fails since missing ~/.virtualenvs/pip-test3/bin/nosetests
  • 问题 #2我是否遗漏了有关add2virtualenv工作方式的某些内容?
  • Question #1 Rephrased Is there a better method than add2virtualenv that allows multiple virtualenvs to reference one Python package that is not installed in my Python 2.7 site-packages?
  • Question #3 If there is a method to install a shared Python package into multiple virtualenvs, is there a performance penalty that isn't there compared to installing Python packages separately into each virtualenv?
  • Question #4 Should I just give up on conserving disk space and stick with my current workflow?
4

1 回答 1

11

Unless you are doing development on an embedded system, I find that chasing disk space in this way is always counter-productive. It took me a long time to reach this realization, because I grew up when a very large hard drive was a few megabytes in size, and RAM was measured in K. But today, unless you are under very special and unusual constraints, the benefit of having your projects be orthogonal (you can delete any directories on your system anywhere outside your project, and have its Python packages still there) seems to always far outweigh the disk-space benefit that, if you're busy developing, you'll never — in my experience — even notice anyway.

So I guess that's the lesson I'm offering from my own experience: you'll never notice the disk space you've lost, but you will notice it if trying to clean up a directory in one place on your disk breaks projects under development somewhere else.

于 2010-09-11T21:59:44.510 回答