我知道 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):
/usr/lib/python2.7/dist-packages
:这是我的 ipython、scipy、numpy、matplotlib 的全局安装——我发现单独安装这些软件包既困难又费时(及其所有依赖项)如果它们不能通过 scipy 堆栈获得./usr/local/lib/python2.7/site-packages
:这是空的,我认为除非我从源代码安装包,否则它会在 Ubuntu 上保持这种状态./usr/local/lib/python2.7/dist-packages
:这里有非常重要的天文学本地包,特别是与PyRAF、STScI等相关的包,难度极大单独安装也很耗时./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./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./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-packages 等(可能还有其他)虚拟环境.
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.
这是我的问题:
dist-packages
目录中的包?dist-packages
目录中更新我的 scipy、ipython 等全局安装时,这是否也会更新/更改我的虚拟环境使用的包(以及它最初使用的包)在virtualenv创建期间得到)?/usr/local/lib/python2.7/dist-packages
还是 /usr/local/lib/python2.7/site-packages
?dist-packages
directories for virtual environments that are created in the future?dist-packages
directories, will this also update/change the packages that my virtual environment uses (and which it originally got during virtualenv creation)? /usr/local/lib/python2.7/dist-packages
, or /usr/local/lib/python2.7/site-packages
?提前感谢您的帮助!
这可能是对 PYTHONPATH
的合法使用 - virtualenv
不涉及的环境变量,它使用与环境变量 PATH
相同的语法,在 bash PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages
在 .bashrc 或类似文件中.如果你走这条路,
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,
您根本不必告诉您的虚拟环境,它不会尝试更改它.
You don't have to tell your virtual environment about this at all, it won't try to change it.
不需要重新链接,并且
如果你安装它们,它仍然会去任何地方(pip install
对于我的 Ubuntu 总是使用/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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!