如何让 virtualenv 在 Ubuntu 上使用 dist-packages?

How to get virtualenv to use dist-packages on Ubuntu?(如何让 virtualenv 在 Ubuntu 上使用 dist-packages?)
本文介绍了如何让 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 的全局安装——我发现单独安装这些软件包既困难又费时(及其所有依赖项)如果它们不能通过 scipy 堆栈获得.
  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-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.

这是我的问题:

  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 相同的语法,在 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,

  1. 您根本不必告诉您的虚拟环境,它不会尝试更改它.

  1. 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)