Python 将 Anaconda 安装到虚拟环境中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16727171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Anaconda into a Virtual Environment
提问by Fomite
I've currently got a working installation of the Enthought Python Distributionon my machine that I don't want to necessarily disrupt, but I'd like to look at moving over to Anacondafrom Continuum.
我目前在我的机器上安装了Enthought Python Distribution,我不想破坏它,但我想考虑从 Continuum转移到Anaconda。
I can easily install Anaconda into the virtualenv directory I create, but I'm not sure how to tell that virtualenv to use the anaconda-version of Python. If I was telling my whole system to use it I can alter .bash_profilewith something like export PATH="/DIRECTORIES/anaconda/bin:$PATH. Is there a way to do that within a virtualenv?
我可以轻松地将 Anaconda 安装到我创建的 virtualenv 目录中,但我不确定如何告诉该 virtualenv 使用 Python 的 anaconda 版本。如果我告诉我的整个系统使用它,我可以.bash_profile用类似export PATH="/DIRECTORIES/anaconda/bin:$PATH. 有没有办法在 virtualenv 中做到这一点?
采纳答案by Charl Botha
I just tested the Anaconde 1.6 installer from http://continuum.io/downloads
我刚刚从http://continuum.io/downloads测试了 Anaconde 1.6 安装程序
After downloading, I did:
下载后,我做了:
bash Anaconda-1.6.0-Linux-x86_64.sh
If you take the defaults, you'll end up with a directory anacondain your home directory, completely separate from your EPD or system Python installation.
如果采用默认值,您将anaconda在主目录中得到一个目录,与 EPD 或系统 Python 安装完全分开。
To activate the anaconda installation's default environment, do the following:
要激活 anaconda 安装的默认环境,请执行以下操作:
source $HOME/anaconda/bin/activate ~/anaconda
All Python commands will now come from the default Anaconda environment in $HOME/anaconda, which is itself a kind of a virtual environment. You can create sub-environments with e.g. conda create -n myenv1 ipython scipy, but this is not necessary.
所有 Python 命令现在都来自 中的默认 Anaconda 环境$HOME/anaconda,它本身就是一种虚拟环境。您可以使用 eg 创建子环境conda create -n myenv1 ipython scipy,但这不是必需的。
As a side note, you can also use pip(also in $HOME/anaconda/bin) to install PyPI packages into your Anaconda default environment (it has pipinstalled by default) or any of the sub-environments (in which case you should first install pipinto the sub-environment using conda install -n myenv1 pip).
作为旁注,您还可以使用pip(也在$HOME/anaconda/bin)将 PyPI 包安装到您的 Anaconda 默认环境(默认情况下已pip安装)或任何子环境(在这种情况下,您应该首先pip使用conda install -n myenv1 pip)。
It is possible to install parts of Anaconda manually into an existing virtualenv, but using their installer is by far the easiest way to test and use, without affecting any of your existing Python installations.
可以将部分 Anaconda 手动安装到现有的 virtualenv 中,但使用它们的安装程序是迄今为止最简单的测试和使用方法,不会影响任何现有的 Python 安装。
回答by alexhb
When you create your virtualenv use the -pflag to give it the path to the Python executable you want to use:
创建 virtualenv 时,请使用该-p标志为其指定要使用的 Python 可执行文件的路径:
virtualenv -p /path/to/python-anaconda-version

![Python if row[0] in row[1] 打印行](/res/img/loading.gif)