如何让virtualenv在Ubuntu上使用dist-packages? [英] How to get virtualenv to use dist-packages on Ubuntu?

查看:127
本文介绍了如何让virtualenv在Ubuntu上使用dist-packages?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道virtualenv如果在创建新的虚拟环境时未通过--no-site-packages参数,则会将/usr/local/lib/python2.7/site-packages中的软件包(对于Python 2.7)链接到新创建的虚拟环境.在Ubuntu 12.04 LTS上,我在三个位置可以安装Python 2.7软件包(使用默认的Ubuntu提供的Python 2.7安装):

I know that virtualenv, if not passed the --no-site-packages argument when creating a new virtual environment, will link the packages in /usr/local/lib/python2.7/site-packages (for Python 2.7) with a newly-created virtual environment. On Ubuntu 12.04 LTS, I have three locations where Python 2.7 packages can be installed (using the default, Ubuntu-supplied Python 2.7 installation):

  1. /usr/lib/python2.7/dist-packages:这是我的ipython,scipy,numpy,matplotlib的全局安装-如果无法通过密码栈.
  2. /usr/local/lib/python2.7/site-packages:这是空的,除非我从源代码安装软件包,否则我认为它将在Ubuntu上保持这种状态.
  3. /usr/local/lib/python2.7/dist-packages:它具有非常重要的本地天文软件包,尤其是与PyRAF,STScI等相关的软件包,单独安装非常困难且耗时.
  1. /usr/lib/python2.7/dist-packages: this has my global installation of ipython, scipy, numpy, matplotlib – packages that I would find difficult and time-consuming to install individually (and all their dependences) if they were not available via the scipy stack.
  2. /usr/local/lib/python2.7/site-packages: this is empty, and I think it will stay that way on Ubuntu unless I install a package from source.
  3. /usr/local/lib/python2.7/dist-packages: this has very important local packages for astronomy, notably those related to PyRAF, STScI, etc., and they are extremely difficult and time-consuming to install individually.

请注意,我的系统上不存在诸如/usr/lib/python2.7/site-packages之类的全局目录.还要注意,我在ipython,scipy等设备上的全局安装使我可以即时使用这些软件包,而不必每次都获取/激活虚拟环境.

Note that a global directory such as /usr/lib/python2.7/site-packages does not exist on my system. Note also that my global installation of ipython, scipy, etc. lets me use those packages on-the-fly without having to source/activate a virtual environment every time.

自然,我现在想使用virtualenv在用户主目录中创建一个虚拟环境,该虚拟环境将为以后的项目提供源/激活.但是,我希望这个虚拟环境在创建时能够链接/复制我在上面列表中位置(1)和(3)的所有程序包.这样做的主要原因是我不想通过pip install进程(如果可能的话)为该(可能还有其他)虚拟机重新安装ipython,scipy,astro软件包等.环境.

Naturally, I now want to use virtualenv to create one virtual environment in my user home directory which I will source/activate for my future projects. However, I would like this virtual environment, while being created, to link/copy all of my packages in locations (1) and (3) in the list above. The main reason for this is that I don't want to go through the pip install process (if it is even possible) to re-install ipython, scipy, the astro-packages, etc. for this (and maybe other) virtual environments.

这是我的问题:

  1. 我是否可以指定给virtualenv,以便它链接/复制这两个dist-packages目录中的软件包,以供将来创建的虚拟环境使用?
  2. 当我最终在两个dist-packages目录中更新scipy,ipython等的全局安装时,是否还会更新/更改我的虚拟环境使用的软件包(以及在virtualenv创建过程中最初获得的软件包)?
  3. 如果我曾经在Ubuntu上从源代码安装软件包,它将装入/usr/local/lib/python2.7/dist-packages还是/usr/local/lib/python2.7/site-packages?
  1. Is there a way for me to specify to virtualenv that I would like it to link/copy packages in these two dist-packages directories for virtual environments that are created in the future?
  2. When I eventually update my global installation of scipy, ipython, etc. in the two dist-packages directories, will this also update/change the packages that my virtual environment uses (and which it originally got during virtualenv creation)?
  3. If I ever install a package from source on Ubuntu, will it go in /usr/local/lib/python2.7/dist-packages, or /usr/local/lib/python2.7/site-packages?

提前感谢您的帮助!

推荐答案

这可能是PYTHONPATH的合法使用-virtualenv不会触及的环境变量,其语法与环境变量PATH 、. bashrc或类似版本中的bash PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages中.如果您遵循此路径,

This might be a legitimate use of PYTHONPATH - an environmental variable that virtualenv doesn't touch, which uses the same syntax as the environmental variable PATH, in bash PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages in a .bashrc or similar. If you followed this path,

  1. 您完全不必告诉虚拟环境,它也不会尝试更改它.

  1. You don't have to tell your virtual environment about this at all, it won't try to change it.

不需要重新链接,并且

即使将其安装在虚拟环境之外,它仍然可以运用于任何地方(对于我的Ubuntu,pip install始终使用/usr/local/lib/python2.7/dist-packages/).如果您是在虚拟环境中(在激活状态下)安装它们,则当然会将其放置在虚拟环境中.

That will still go wherever it would have gone (pip install always uses /usr/local/lib/python2.7/dist-packages/ for my Ubuntu) if you install them outside of your virtual environment. If you install them from within your virtual environment (while it's activated) then of course it'll be put in the virtualenvironment.

这篇关于如何让virtualenv在Ubuntu上使用dist-packages?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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