标签归档:conda

如何更改默认的Anaconda python环境

问题:如何更改默认的Anaconda python环境

我已经安装了Anaconda,并创建了两个额外的环境:py3k(具有Python 3.3)和py34(具有Python 3.4)。除此之外,我还有一个默认环境“ root”,该环境由Anaconda安装程序默认创建,并包含Python 2.7。最后一个是默认值,每当我从终端启动“ ipython”时,它就会给我2.7版本。为了使用Python 3.4,我需要发出命令(在shell中)

source activate py34
ipython

它将默认环境更改为Python 3.4。这很好用,但是很烦人,因为我大部分时间都在使用Python 3.4而不是Python 2.7(我出于教学目的持有这是一个很长的故事)。无论如何,我想知道如何将默认环境更改为Python 3.4,但要记住我不想从头开始重新安装所有内容。

I’ve installed Anaconda and created two extra environments: py3k (which holds Python 3.3) and py34 (which holds Python 3.4). Besides those, I have a default environment named ‘root’ which the Anaconda installer created by default and which holds Python 2.7. This last one is the default, whenever I launch ‘ipython’ from the terminal it gives me version 2.7. In order to work with Python 3.4, I need to issue the commands (in the shell)

source activate py34
ipython

which change the default environment to Python 3.4. This works fine, but it’s annoying since most of the time I work on Python 3.4, instead of Python 2.7 (which I hold for teaching purposes, it’s a rather long story). Anyway, I’ll like to know how to change the default environment to Python 3.4, bearing in mind that I don’t want to reinstall everything from scratch.


回答 0

如果您只想更改为其他环境,请使用

source activate environment-name

(您可以environment-name使用`conda create创建)


通常,最好只是创建新环境。但是,如果您确实想在默认环境中更改Python版本,则可以执行以下操作:

首先,通过运行确保您拥有最新版本的conda

conda update conda

然后跑

conda install python=3.5

这将尝试将根环境中的所有软件包更新为Python 3版本。如果不可能(例如,因为某些软件包不是为Python 3.5构建的),它将向您显示一条错误消息,指出哪个软件包导致了问题。

如果您使用pip安装了软件包,则必须重新安装它们。

If you just want to change to another environment, use

source activate environment-name

(you can create environment-name with `conda create)


Typically it’s best to just create new environments. However, if you really want to change the Python version in the default environment, you can do so as follows:

First, make sure you have the latest version of conda by running

conda update conda

Then run

conda install python=3.5

This will attempt to update all your packages in your root environment to Python 3 versions. If it is not possible (e.g., because some package is not built for Python 3.5), it will give you an error message indicating which package(s) caused the issue.

If you installed packages with pip, you’ll have to reinstall them.


回答 1

概述
出于兼容性原因,某些人具有多个具有不同版本python的Anaconda环境。在这种情况下,您应该具有一个设置默认环境的脚本。使用这种方法,您可以保留您在环境中使用的python版本。

以下假设environment_name是您的环境的名称

Mac / Linux:
编辑您的bash配置文件,使最后一行是source activate environment_name。在Mac OSX中,这是〜/ .bash_profile,在其他环境中,这可能是〜/ .bashrc

示例:
这是我在Mac OSX上的操作方式

  1. 打开终端并输入:

    nano ~/.bash_profile

  2. 转到文件末尾并键入以下内容,其中“ p3.5”是我的环境:

    source activate p3.5

  3. 退出文件。启动一个新的终端窗口。

  4. 输入以下内容以查看活跃的环境

    conda info -e

结果表明,默认情况下我正在使用我的p3.5环境。

对于Windows:在打开命令提示符时,
使用创建一个命令文件(.cmd),activate environment_name并按照以下说明执行该文件。

  1. 创建一个批处理文件命令,例如“ my_conda.cmd”,将其放入“应用程序数据”文件夹中。
  2. 将其配置为在每次打开时自动启动cmd。此设置位于注册表中:注册表
    项:HKCU \ SOFTWARE \ Microsoft \ Command处理器
    值:自动运行
    类型:REG_EXPAND_SZ
    数据:“%AppData%\ my_conda.cmd”

从这个答案:https//superuser.com/a/302553/143794

Overview
Some people have multiple Anaconda environments with different versions of python for compatibility reasons. In this case, you should have a script that sets your default environment. With this method, you can preserve the versions of python you use in your environments.

The following assumes environment_name is the name of your environment

Mac / Linux:
Edit your bash profile so that the last line is source activate environment_name. In Mac OSX this is ~/.bash_profile, in other environments this may be ~/.bashrc

Example:
Here’s how i did it on Mac OSX

  1. Open Terminal and type:

    nano ~/.bash_profile

  2. Go to end of file and type the following, where “p3.5” is my environment:

    source activate p3.5

  3. Exit File. Start a new terminal window.

  4. Type the following to see what environment is active

    conda info -e

The result shows that I’m using my p3.5 environment by default.

For Windows:
Create a command file (.cmd) with activate environment_name and follow these instructions to have it execute whenever you open a command prompt

  1. Create a batch file command, e.g. “my_conda.cmd”, put it in the Application Data folder.
  2. Configure it to be started automatically whenever you open cmd. This setting is in Registry:
    key: HKCU\SOFTWARE\Microsoft\Command Processor
    value: AutoRun
    type: REG_EXPAND_SZ
    data: “%AppData%\my_conda.cmd”

from this answer: https://superuser.com/a/302553/143794


回答 2

在Linux下,有一种更简单的方法可以通过修改~/.bashrc或来设置默认环境。~/.bash_profile 最后,您会发现类似

# added by Anaconda 2.1.0 installer
export PATH="~/anaconda/bin:$PATH"

替换为

# set python3 as default
export PATH="~/anaconda/envs/python3/bin:$PATH"

这就是全部。

Under Linux there is an easier way to set the default environment by modifying ~/.bashrc or ~/.bash_profile At the end you’ll find something like

# added by Anaconda 2.1.0 installer
export PATH="~/anaconda/bin:$PATH"

Replace it with

# set python3 as default
export PATH="~/anaconda/envs/python3/bin:$PATH"

and thats all there is to it.


回答 3

对于Windows,Anaconda附带了Anaconda Prompt,它是cmd的快捷方式,可用于运行conda命令,而无需在PATH变量中添加anaconda。找到它的位置,复制并重命名该副本(例如myenv_prompt)。右键单击myenv_prompt,然后在上下文菜单中选择属性。

“ 属性”窗口的“ 目标”表单应该已经用文本填充,例如%windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\ 该命令的三个部分:1)启动… \ cmd.exe 2)运行… \使用环境3)\ acitvate.bat … \ Miniconda3 \

将第3部分更改为您想要默认设置的环境路径(例如myenv),即填写目标表单,例如%windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\envs\myenv

现在,myenv_prompt将充当以myenv作为python的默认环境启动cmd的快捷方式。您可以将此快捷方式保留在开始菜单中或固定在任务栏中。

此方法的一个优点是您可以创建一些快捷方式,每个快捷方式都具有不同的环境作为默认环境。您也可以通过 “属性”窗口的表单中填写“ 开始”来设置默认文件夹

希望这可以帮助

PS:不需要查找Anaconda Prompt,可以通过更改任何快捷方式的目标来完成。但是您将需要知道cmd.exe的路径和activate.bat

For windows Anaconda comes with Anaconda Prompt which is a shortcut to cmd and can be used run conda commands without adding anaconda in PATH variable. Find the location of it, copy and rename the copy (say myenv_prompt). Right click myenv_prompt and select properties in the context menu.

The Target form of Properties window should already be filled with text, something like %windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\ There are three parts of this command 1)start …\cmd.exe 2)run …\acitvate.bat with environment 3)…\Miniconda3\

Change 3rd part to path of the environment (say myenv) you want as default i.e. fill the Target form something like %windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\envs\myenv

Now myenv_prompt will act as shortcut to start cmd with myenv as the default environment for python. This shortcut you can keep in start menu or pinned in taskbar.

One advantage of this method is that you can create a few shortcuts each having different environment as default environment. Also you can set the default folder by filling Start in form of the Properties window

Hope this helps

PS:It is not required to find Anaconda Prompt and can be done by changing target of any shortcut. But you will require to know path of cmd.exe and activate.bat


回答 4

永久更改

conda install python={version}

临时更改

查看您的环境

运行conda info --envs终端窗口或Anconda上提示

如果未显示您要安装的环境

运行conda create -n py36 python=3.6 anacondapython 3.6更改版本作为您的首选

激活环境(使用Anaconda提示符)

运行activate envnmeenvnme,您可以conda info --envs在运行时通过此命令作为示例conda info --envs显示

base * C:\Users\DulangaHeshan\Anaconda3 py36 C:\Users\DulangaHeshan\Anaconda3\envs\py36

然后跑 activate py36

检查运行 python --version

在Windows中,优良作法是在激活另一个环境之前先停用它。 https://docs.conda.io/projects/conda/zh/latest/user-guide/tasks/manage-environments.html?highlight=deactivate%20environment

Change permanent

conda install python={version}

Change Temporarily

View your environments

run conda info --envs on your terminal window or an Anconda Prompt

If It doesn’t show environment that you want to install

run conda create -n py36 python=3.6 anaconda for python 3.6 change version as your prefer

Activating an environment (use Anaconda prompt)

run activate envnme envnme you can find by this commandconda info --envs as a example when you run conda info --envs it show

base * C:\Users\DulangaHeshan\Anaconda3 py36 C:\Users\DulangaHeshan\Anaconda3\envs\py36

then run activate py36

to check run python --version

In Windows, it is good practice to deactivate one environment before activating another. https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html?highlight=deactivate%20environment


回答 5

正确的答案(截至2018年12月)是…你不能。升级conda install python=3.6可能会起作用,但是如果您有必需的但不能卸载的软件包,则可能无法升级。

Anaconda使用默认环境命名,base并且您不能使用相同的名称创建新的环境(例如python 3.6)。这是故意的。如果您希望基本的Anaconda为python 3.6,则正确的方法是为python 3.6安装Anaconda。作为软件包管理器,Anaconda的目标是封装不同的环境,因此为什么您必须在其中激活激活资源以及为什么不能随便安静地切换基本软件包,因为这可能会导致生产系统出现许多问题。

The correct answer (as of Dec 2018) is… you can’t. Upgrading conda install python=3.6 may work, but it might not if you have packages that are necessary, but cannot be uninstalled.

Anaconda uses a default environment named base and you cannot create a new (e.g. python 3.6) environment with the same name. This is intentional. If you want your base Anaconda to be python 3.6, the right way to do this is to install Anaconda for python 3.6. As a package manager, the goal of Anaconda is to make different environments encapsulated, hence why you must source activate into them and why you can’t just quietly switch the base package at will as this could lead to many issues on production systems.


回答 6

我对这里提出的任何答案都不满意,因为激活环境在我的平台上花费了几秒钟(无论出于何种原因)

我修改了路径变量,以使我想要作为默认环境的优先于实际默认环境。

就我而言,我使用以下命令针对“ py35”环境完成此操作:

setx PATH "%userprofile%\Anaconda3\envs\py35\;%PATH%"
setx PATH "%userprofile%\Anaconda3\envs\py35\Scripts;%PATH%"

要查找环境的存储位置,请激活它并输入where python。我不确定这种方法是否有缺点。由于它还会更改conda可执行文件的默认路径。如果是这种情况,请发表评论。

I wasn’t satisfied with any of the answers presented here, since activating an environment takes a few seconds on my platform (for whatever reason)

I modified my path variable so that the environment I want as default has priority over the actual default.

In my case I used the following commands to accomplish that for the environment “py35”:

setx PATH "%userprofile%\Anaconda3\envs\py35\;%PATH%"
setx PATH "%userprofile%\Anaconda3\envs\py35\Scripts;%PATH%"

to find out where your environment is stored, activate it and enter where python. I’m not sure yet if this approach has any downsides. Since it also changes the default path of the conda executable. If that should be the case, please comment.


回答 7

使用anaconda安装库时,出现了此错误。我的版本从Python 3. *升级到2.7,很多东西停止了工作。我发现的最佳解决方案是首先查看可用的最新版本:

conda search python

然后更新到所需的版本:

conda install python=3.*.*

资料来源:http : //chris35wills.github.io/conda_python_version/

其他有用的命令:

conda info
python --version

I got this when installing a library using anaconda. My version went from Python 3.* to 2.7 and a lot of my stuff stopped working. The best solution I found was to first see the most recent version available:

conda search python

Then update to the version you want:

conda install python=3.*.*

Source: http://chris35wills.github.io/conda_python_version/

Other helpful commands:

conda info
python --version

回答 8

在桌面或任务栏上创建anaconda提示的快捷方式,然后在该快捷方式的属性中确保将“ Target:”中的最后一个路径修改为您环境的路径:

C:\ Users \ BenBouali \ Anaconda3 \将更改为C:\ Users \ BenBouali \ Anaconda3 \ envs \ tensorflow-gpu

预习

这样,您可以在单击某个快捷方式时使用该快捷方式打开特定的环境,您也可以将其添加到您的路径中,现在您只需键入快捷方式的名称就可以从Windows运行框中运行它。

Create a shortcut of anaconda prompt onto desktop or taskbar, and then in the properties of that shortcut make sure u modify the last path in “Target:” to the path of ur environment:

C:\Users\BenBouali\Anaconda3\ WILL CHANGE INTO C:\Users\BenBouali\Anaconda3\envs\tensorflow-gpu

preview

and this way u can use that shortcut to open a certain environment when clicking it, you can add it to ur path too and now you’ll be able to run it from windows run box by just typing in the name of the shortcut.


回答 9

在Windows上,创建包含以下行的批处理文件:

start cmd /k "C:\Anaconda3\Scripts\activate.bat C:\Anaconda3 & activate env"

引号中包含的第一个路径是Anaconda安装中的activate.bat文件的路径。您系统上的路径可能不同。当然,激活命令后面的名称应该是您所需的环境名称。

然后在需要打开Anaconda提示符时运行批处理文件。

On Windows, create a batch file with the following line in it:

start cmd /k "C:\Anaconda3\Scripts\activate.bat C:\Anaconda3 & activate env"

The first path contained in quotes is the path to the activate.bat file in the Anaconda installation. The path on your system might be different. The name following the activate command of course should be your desired environment name.

Then run the batch file when you need to open an Anaconda prompt.


回答 10

加载你的 “基地”环境-如OP的py34-当你加载你的终端/壳。

如果您使用Bash,请输入以下行:

conda activate py34

在您.bash_profile(或.bashrc)中:

$ echo 'conda activate py34' >> ~/.bash_profile

每次运行新的终端时,py34都会加载conda环境。

Load your “base” environment — as OP’s py34 — when you load your terminal/shell.

If you use Bash, put the line:

conda activate py34

in your .bash_profile (or .bashrc):

$ echo 'conda activate py34' >> ~/.bash_profile

Every time you run a new terminal, conda environment py34 will be loaded.


如何激活Anaconda环境

问题:如何激活Anaconda环境

我在Windows 8上,使用Anaconda 1.7.5 64bit。

我创建了一个新的Anaconda环境

conda create -p ./test python=2.7 pip

来自C:\Pr\TEMP\venv\

效果很好(有一个带有新python发行版的文件夹)。康达告诉我输入

activate C:\PR\TEMP\venv\test

激活环境,但是返回:

No environment named "C:\PR\temp\venv\test" exists in C:\PR\Anaconda\envs

如何激活环境?我究竟做错了什么?

I’m on Windows 8, using Anaconda 1.7.5 64bit.

I created a new Anaconda environment with

conda create -p ./test python=2.7 pip

from C:\Pr\TEMP\venv\.

This worked well (there is a folder with a new python distribution). conda tells me to type

activate C:\PR\TEMP\venv\test

to activate the environment, however this returns:

No environment named "C:\PR\temp\venv\test" exists in C:\PR\Anaconda\envs

How can I activate the environment? What am I doing wrong?


回答 0

如果发生这种情况,则需要为您的环境设置PATH(以便从环境和Windows上的Scripts \中获取正确的Python)。

假设您使用以下方法创建了一个名为py33的环境:

conda create -n py33 python=3.3 anaconda

在默认情况下,这里是在Anaconda \ envs中创建的文件夹,因此您需要将PATH设置为:

set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH%

现在它应该可以在命令窗口中工作:

activate py33

上面的行是Windows,等同于Mac和Linux教程中通常显示的代码:

$ source activate py33

更多信息:https : //groups.google.com/a/continuum.io/forum/#!topic/ anaconda/ 8T8i11gO39U

anaconda是否为每个新环境创建一个单独的PYTHONPATH变量?

If this happens you would need to set the PATH for your environment (so that it gets the right Python from the environment and Scripts\ on Windows).

Imagine you have created an environment called py33 by using:

conda create -n py33 python=3.3 anaconda

Here the folders are created by default in Anaconda\envs, so you need to set the PATH as:

set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH%

Now it should work in the command window:

activate py33

The line above is the Windows equivalent to the code that normally appears in the tutorials for Mac and Linux:

$ source activate py33

More info: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/8T8i11gO39U

Does `anaconda` create a separate PYTHONPATH variable for each new environment?


回答 1

使用cmd代替Powershell! 我花了2个小时才切换到cmd,然后才起作用!

创建环境:

conda create -n your_environment_name

查看conda环境列表:

conda env list

激活您的环境:

conda activate your_environment_name

那是所有人

Use cmd instead of Powershell! I spent 2 hours before I switched to cmd and then it worked!

create Environment:

conda create -n your_environment_name

see list of conda environments:

conda env list

activate your environment:

conda activate your_environment_name

That’s all folks


回答 2

请注意,用于激活环境的命令在Conda 4.4版中已更改。激活一个环境的推荐的方法是现在conda activate myenv,而不是source activate myenv。要启用新语法,您应该修改 .bashrc文件。该行当前显示类似

export PATH="<path_to_your_conda_install>/bin:$PATH"

应该改为

. <path_to_your_conda_install>/etc/profile.d/conda.sh

这只会将conda命令添加到路径,而尚未激活base环境(以前称为root)。为此,添加另一行

conda activate base

在第一个命令之后。请参阅Anaconda自2017年12月以来的博客文章中的所有详细信息。(我认为该页面目前缺少两行之间的换行符.../conda.shconda activate base)。

(此答案对Linux有效,但对Windows和Mac也可能适用)

Note that the command for activating an environment has changed in Conda version 4.4. The recommended way of activating an environment is now conda activate myenv instead of source activate myenv. To enable the new syntax, you should modify your .bashrc file. The line that currently reads something like

export PATH="<path_to_your_conda_install>/bin:$PATH"

Should be changed to

. <path_to_your_conda_install>/etc/profile.d/conda.sh

This only adds the conda command to the path, but does not yet activate the base environment (which was previously called root). To do also that, add another line

conda activate base

after the first command. See all the details in Anaconda’s blog post from December 2017. (I think that this page is currently missing a newline between the two lines, it says .../conda.shconda activate base).

(This answer is valid for Linux, but it might be relevant for Windows and Mac as well)


回答 3

以前所有的答案似乎都是过时的。

conda activateconda4.4和4.6中引入。

conda activate:重新激活了环境激活的逻辑和机制。与康达4.4,conda activate并且conda deactivate是现在用于激活和停用环境的首选命令。您会发现它们比以前的conda版本中的source activateand source deactivate命令更加灵活。该conda activate命令还具有(1)在所有OS,shell 和平台上通用的优势,以及(2)与其他包(例如python virtualenv的Activate脚本)中的脚本没有路径冲突。

例子

conda create -n venv-name python=3.6
conda activate -n venv-name
conda deactivate

这些新的子命令在“ Aanconda提示”和“ Anaconda Powershell提示”中自动可用。要conda activate每个shell(普通cmd.exe和powershell)中使用,请在Windows的每个shell中检查暴露conda命令

参考资料

All the former answers seem to be outdated.

conda activate was introduced in conda 4.4 and 4.6.

conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You’ll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv’s activate script.

Examples

conda create -n venv-name python=3.6
conda activate -n venv-name
conda deactivate

These new sub-commands are available in “Aanconda Prompt” and “Anaconda Powershell Prompt” automatically. To use conda activate in every shell (normal cmd.exe and powershell), check expose conda command in every shell on Windows.

References


回答 4

从错误消息中可以看到,您指定的路径是错误的。像这样尝试:

activate ..\..\temp\venv\test

但是,当我需要安装Anaconda时,我从这里下载了它并将其安装到默认路径(C:\Anaconda),而不是将此路径放置到环境变量中,因此现在将Anacondas解释器用作默认路径。例如,如果您使用的是PyCharm,则可以在那里直接指定解释器。

As you can see from the error message the paths, that you specified, are wrong. Try it like this:

activate ..\..\temp\venv\test

However, when I needed to install Anaconda, I downloaded it from here and installed it to the default paths (C:\Anaconda), than I put this path to the environment variables, so now Anacondas interpreter is used as default. If you are using PyCharm, for example, you can specify the interpreter there directly.


回答 5

以下是它对我的工作方式

  1. C:\ Windows \ system32>设置CONDA_ENVS_PATH = d:\您的\位置
  2. C:\ Windows \ system32> conda信息

显示新的环境路径

  1. C:\ Windows \ system32> conda创建-n YourNewEnvironment –clone = root

克隆默认的根环境

  1. C:\ Windows \ system32>激活YourNewEnvironment

停用环境“ d:\ YourDefaultAnaconda3” …停用环境“ d:\ your \ location \ YourNewEnvironment” …

  1. [YourNewEnvironment] C:\ Windows \ system32> conda信息-e

康达环境:

YourNewEnvironment
* d:\ your \ location \ YourNewEnvironment

根d:\ YourDefaultAnaconda3

Below is how it worked for me

  1. C:\Windows\system32>set CONDA_ENVS_PATH=d:\your\location
  2. C:\Windows\system32>conda info

Shows new environment path

  1. C:\Windows\system32>conda create -n YourNewEnvironment –clone=root

Clones default root environment

  1. C:\Windows\system32>activate YourNewEnvironment

Deactivating environment “d:\YourDefaultAnaconda3″… Activating environment “d:\your\location\YourNewEnvironment”…

  1. [YourNewEnvironment] C:\Windows\system32>conda info -e

conda environments: #

YourNewEnvironment
* d:\your\location\YourNewEnvironment

root d:\YourDefaultAnaconda3


回答 6

我曾尝试用Jenkins job(bash)激活env conda activate base ,但是失败了,所以在尝试了很多之后,这个对我有用(CentOS 7):

source /opt/anaconda2/bin/activate base

I’ve tried to activate env from Jenkins job (in bash) with conda activate base and it failed, so after many tries, this one worked for me (CentOS 7) :

source /opt/anaconda2/bin/activate base

回答 7

假设您的环境名称为‘demo’,并且您正在使用anaconda并想创建一个虚拟环境:

(如果您想要python3)

    conda create -n demo python=3

(如果您想要python2)

    conda create -n demo python=2

运行上述命令后,您必须通过以下命令激活环境:

    source activate demo 

let’s assume your environment name is ‘demo’ and you are using anaconda and want to create a virtual environment:

(if you want python3)

    conda create -n demo python=3

(if you want python2)

    conda create -n demo python=2

After running above command you have to activate the environment by bellow command:

    source activate demo 

回答 8

对我来说,使用Anaconda Prompt代替cmd或PowerShell是关键。

在Anaconda Prompt中,我要做的就是 activate XXX

For me, using Anaconda Prompt instead of cmd or PowerShell is the key.

In Anaconda Prompt, all I need to do is activate XXX


回答 9

我也有相同的想法,似乎已在源代码中进行了修复。

I was having the same, a fix seems to have been made in the source.


回答 10

正如@Simba正确回答的那样,自4.6起conda env发生了变化。Conda activate (env-name)彻底推翻source activate (env-name),但并非没有挑战。conda activate经常强迫你的环境建立基础,让你看到类似的东西。因此,将大量错误抛给您。这也可能是因为auto_activate_base设置为True。

您可以使用以下命令进行检查

conda config --set auto_activate_base False

source ~/.bashrc

要重新激活使用此

conda config --set auto_activate_base True

source ~/.bashrc

just as @Simba has rightly answered alot has changed in the conda env since 4.6. Conda activate (env-name) overthrew source activate (env-name) for good but not without it own challenges. conda activate oftentimes force your environment to base and make u see something like . Therefore throwing loads of error back at you. This can also be because auto_activate_base is set to True.

You can check this by using the following command

conda config --set auto_activate_base False

source ~/.bashrc.

And To reactivate use this

conda config --set auto_activate_base True

source ~/.bashrc


回答 11

窗口: conda激活environment_name

Mac:conda激活environment_name

Window: conda activate environment_name

Mac: conda activate environment_name


如何在Anaconda(Conda)环境中跟踪点子安装的软件包?

问题:如何在Anaconda(Conda)环境中跟踪点子安装的软件包?

我已经安装并一直在使用Anaconda Python发行版,并且已经开始使用Anaconda(Conda)环境。我可以使用标准conda install...命令将分发包中的软件包放入我的环境中,但要使用其他pip install在活动环境中需要使用的东西(例如Flask-WTF,flask-sqlalchemy和alembic)。但是,当我查看环境的内容时,无论是在目录中还是使用conda list这些pip installed包,都不会显示。

使用pip freezepip list仅列出我曾经安装的每个软件包。

有没有办法跟踪我的每个Anaconda env(安装pipconda安装的)中的物品?

I’ve installed and have been using the Anaconda Python distribution, and I have started using the Anaconda (Conda) environment. I can use the standard conda install... command to put packages from the distribution into my environments, but to use anything outside (i.e. Flask-WTF, flask-sqlalchemy, and alembic) I need to use pip install in the active environment. However, when I look at the contents of the environment, either in the directory, or using conda list these pip installed packages don’t show up.

Using pip freeze and pip list just lists every package I’ve ever installed.

Is there a way to keep track of what is in each of my Anaconda envs (both pip and conda installed)?


回答 0

conda-env现在可以自动执行此操作(如果pip与conda一起安装)。

您可以使用用于迁移环境的导出工具来查看其工作原理:

conda env export -n <env-name> > environment.yml

该文件将列出conda软件包和pip软件包:

name: stats
channels:
  - javascript
dependencies:
  - python=3.4
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

如果您希望继续导出环境,请移至environment.yml新的主机并运行:

conda env create -f path/to/environment.yml

conda-env now does this automatically (if pip was installed with conda).

You can see how this works by using the export tool used for migrating an environment:

conda env export -n <env-name> > environment.yml

The file will list both conda packages and pip packages:

name: stats
channels:
  - javascript
dependencies:
  - python=3.4
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

If you’re looking to follow through with exporting the environment, move environment.yml to the new host machine and run:

conda env create -f path/to/environment.yml

回答 1

conda将仅跟踪其安装的软件包。并pip会为您提供使用pip安装程序本身安装的软件包,或setuptoolssetup.pyconda构建中使用的软件包生成的egg信息。因此,您基本上有三个选择。

  1. 你可以采取的联合conda listpip freeze和管理使用安装的软件包conda(在这个节目conda list用)conda包管理器,并确保安装与个位pip(即秀pip freeze,但不是在conda list)与pip

  2. 仅在和环境中安装pythonpip然后使用distribute打包和管理所有内容pip。(如果您使用的是Windows,那么这并不是一件容易的事…)

  3. 构建自己的conda软件包,并使用进行管理conda

我个人推荐第三个选项,因为它很容易构建conda软件包。在连续体的github帐户上有一个示例食谱的git存储库。但通常可以归结为:

 conda skeleton pypi PACKAGE
 conda build PACKAGE

要不就:

conda pipbuild PACKAGE

同样,一旦构建它们,您就可以将它们上传到https://binstar.org/并从那里安装。

然后,您将使用进行所有管理conda

conda will only keep track of the packages it installed. And pip will give you the packages that were either installed using the pip installer itself or they used setuptools in their setup.py so conda build generated the egg information. So you have basically three options.

  1. You can take the union of the conda list and pip freeze and manage packages that were installed using conda (that show in the conda list) with the conda package manager and the ones that are installed with pip (that show in pip freeze but not in conda list) with pip.

  2. Install in your environment only the python, pip and distribute packages and manage everything with pip. (This is not that trivial if you’re on Windows…)

  3. Build your own conda packages, and manage everything with conda.

I would personally recommend the third option since it’s very easy to build conda packages. There is a git repository of example recipes on the continuum’s github account. But it usually boils down to:

 conda skeleton pypi PACKAGE
 conda build PACKAGE

or just:

conda pipbuild PACKAGE

Also when you have built them once, you can upload them to https://binstar.org/ and just install from there.

Then you’ll have everything managed using conda.


回答 2

有一个conda(new-pypi-install)分支,它可以更好地与pip和PyPI集成。特别是conda列表还将显示pip安装的软件包,conda安装将首先尝试查找conda软件包,如果失败,将使用pip安装软件包。

该分支计划于本周晚些时候合并,以便conda 2.1版将更好地与conda进行点集成。

There is a branch of conda (new-pypi-install) that adds better integration with pip and PyPI. In particular conda list will also show pip installed packages and conda install will first try to find a conda package and failing that will use pip to install the package.

This branch is scheduled to be merged later this week so that version 2.1 of conda will have better pip-integration with conda.


回答 3

我遵循@Viktor Kerkez的回答,并取得了不同的成功。我发现有时候这个食谱

康达骨架pypi包装

康达构建包

看起来一切正常,但我无法成功导入PACKAGE。最近,我在Anaconda用户组上询问了此问题,并从@Travis Oliphant自己那里听说了使用conda构建和管理Anaconda附带的软件包的最佳方法。您可以在此处阅读此主题,但我将在下面描述该方法,以期使OP的问题的答案更加完整…

示例:我将使用conda 2.2.5在Windows上安装出色的prettyplotlib软件包

1a) conda build --build-recipe prettyplotlib

在构建的最后“测试”部分之前,您将看到构建消息看起来都不错。我看到了这个错误

文件“ C:\ Anaconda \ conda-bld \ test-tmp_dir \ run_test.py”,第23行导入None语法错误:无法分配为None测试失败:prettyplotlib-0.1.3-py27_0

1b)进入/ conda-recipes / prettyplotlib并编辑meta.yaml文件。当前,像在步骤1a中一样设置的软件包会导致yaml文件在该test部分中出错。例如,这是我的寻找方式prettyplotlib

test:   # Python imports   imports:
    - 
    - prettyplotlib
    - prettyplotlib

编辑此部分以删除-开头的空白行,并删除多余的prettyplotlib行。在撰写本文时,我发现我需要为使用conda安装的外部软件包编辑这样的大多数meta.yaml文件,这意味着有空白的导入行会导致错误以及给定软件包的冗余导入。

1c)从1a重新运行命令,这一次应该正确完成。在构建结束时,系统会询问您是否要将构建上传到binstar。我输入“否”,然后看到以下消息:

如果您想稍后将此包上传到binstar.org,请键入:

$ binstar上传C:\ Anaconda \ conda-bld \ win-64 \ prettyplotlib-0.1.3-py27_0.tar.bz2

该tar.bz2文件是您现在实际需要安装的构建。

2) conda install C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

按照这些步骤,我已经成功地使用conda安装了Anaconda随附的许多软件包。以前,我已经使用pip安装了其中的一些工具,因此pip uninstall PACKAGE在使用conda安装PACKAGE之前,我已经完成了安装。使用conda,我现在可以通过一种方法来管理(几乎)所有软件包,而无需将conda,pip,easy_install和python setup.py安装混合在一起。

对于上下文,我认为@Travis Oliphant的最新博客文章将对像我这样的人有所帮助,他们不喜欢使用健壮的Python包装的所有内容,但可以肯定当东西“起作用时”。康达似乎是前进的好方法…

I followed @Viktor Kerkez’s answer and have had mixed success. I found that sometimes this recipe of

conda skeleton pypi PACKAGE

conda build PACKAGE

would look like everything worked but I could not successfully import PACKAGE. Recently I asked about this on the Anaconda user group and heard from @Travis Oliphant himself on the best way to use conda to build and manage packages that do not ship with Anaconda. You can read this thread here, but I’ll describe the approach below to hopefully make the answers to the OP’s question more complete…

Example: I am going to install the excellent prettyplotlib package on Windows using conda 2.2.5.

1a) conda build --build-recipe prettyplotlib

You’ll see the build messages all look good until the final TEST section of the build. I saw this error

File “C:\Anaconda\conda-bld\test-tmp_dir\run_test.py”, line 23 import None SyntaxError: cannot assign to None TESTS FAILED: prettyplotlib-0.1.3-py27_0

1b) Go into /conda-recipes/prettyplotlib and edit the meta.yaml file. Presently, the packages being set up like in step 1a result in yaml files that have an error in the test section. For example, here is how mine looked for prettyplotlib

test:   # Python imports   imports:
    - 
    - prettyplotlib
    - prettyplotlib

Edit this section to remove the blank line preceded by the – and also remove the redundant prettyplotlib line. At the time of this writing I have found that I need to edit most meta.yaml files like this for external packages I am installing with conda, meaning that there is a blank import line causing the error along with a redundant import of the given package.

1c) Rerun the command from 1a, which should complete with out error this time. At the end of the build you’ll be asked if you want to upload the build to binstar. I entered No and then saw this message:

If you want to upload this package to binstar.org later, type:

$ binstar upload C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

That tar.bz2 file is the build that you now need to actually install.

2) conda install C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

Following these steps I have successfully used conda to install a number of packages that do not come with Anaconda. Previously, I had installed some of these using pip, so I did pip uninstall PACKAGE prior to installing PACKAGE with conda. Using conda, I can now manage (almost) all of my packages with a single approach rather than having a mix of stuff installed with conda, pip, easy_install, and python setup.py install.

For context, I think this recent blog post by @Travis Oliphant will be helpful for people like me who do not appreciate everything that goes into robust Python packaging but certainly appreciate when stuff “just works”. conda seems like a great way forward…


回答 4

这就是为什么我写Picky的原因:http : //picky.readthedocs.io/

这是一个python软件包,可跟踪在virtualenvs和conda envs中随pip或conda安装的软件包。

This is why I wrote Picky: http://picky.readthedocs.io/

It’s a python package that tracks packages installed with either pip or conda in either virtualenvs and conda envs.


回答 5

我认为这里缺少的是:

>pip install .

要使用setup.py安装本地软件包,它将安装一个对使用相同版本 python的所有 conda env 可见的软件包。注意我正在使用conda版本的pip!

例如,如果我使用的是python2.7,它将本地包放在此处:

/usr/local/anaconda/lib/python2.7/site-packages

如果以后再用python = 2.7(=默认值)创建一个新的conda env:

>conda create --name new

>source activate new

然后执行:

(new)>conda list    // empty - conda is not aware of any packages yet

但是,如果我这样做:

(new)>pip list      // the local package installed above is present

因此,在这种情况下,conda不了解pip包,但是python可以使用该包。

但是,如果我不是安装在本地包(再次使用PIP)后,我已经创建(激活)新康达ENV,现在畅达看到它:

(new)>conda list   // sees that the package is there and was installed by pip

因此,我认为conda和pip之间的交互存在一些问题-即,使用pip从一个conda env中安装本地软件包会使该软件包可用于同一python版本的所有其他conda env(但不能通过conda列表看到)。

I think what’s missing here is that when you do:

>pip install .

to install a local package with a setup.py, it installs a package that is visible to all the conda envs that use the same version of python. Note I am using the conda version of pip!

e.g., if I’m using python2.7 it puts the local package here:

/usr/local/anaconda/lib/python2.7/site-packages

If I then later create a new conda env with python=2.7 (= the default):

>conda create --name new

>source activate new

And then do:

(new)>conda list    // empty - conda is not aware of any packages yet

However, if I do:

(new)>pip list      // the local package installed above is present

So in this case, conda does not know about the pip package, but the package is available to python.

However, If I instead install the local package (again using pip) after I’ve created (and activated) the new conda env, now conda sees it:

(new)>conda list   // sees that the package is there and was installed by pip

So I think the interaction between conda and pip has some issues – ie, using pip to install a local package from within one conda env makes that package available (but not seen via conda list) to all other conda envs of the same python version.


回答 6

conda env export列出环境中的所有conda和pip软件包。conda-env必须安装在conda根目录(conda install -c conda conda-env)中。

编写environment.yml描述当前环境的文件:

conda env export > environment.yml

参考文献:

conda env export lists all conda and pip packages in an environment. conda-env must be installed in the conda root (conda install -c conda conda-env).

To write an environment.yml file describing the current environment:

conda env export > environment.yml

References:


回答 7

我通常会在“ pip”命令之前为要安装软件包的特定环境添加“ bin / pip”文件夹前缀。例如,如果要在环境py34中安装pymc3,则应使用以下命令:

~/anaconda/envs/py34/bin/pip install git+https://github.com/pymc-devs/pymc3 

基本上,您只需要找到环境“ bin / pip”文件夹的正确路径,并将其放在install命令之前即可。

I usually prefix the ‘bin/pip’ folder for the specific environment you want to install the package before the ‘pip’ command. For instance, if you would like to install pymc3 in the environment py34, you should use this command:

~/anaconda/envs/py34/bin/pip install git+https://github.com/pymc-devs/pymc3 

You basically just need to find the right path to your environment ‘bin/pip’ folder and put it before the install command.


回答 8

which pip显示了以下路径:

$ which pip
/home/kmario23/anaconda3/bin/pip

因此,pip install <package-name>使用以下命令导出列表时,无论我安装使用的任何软件包,都必须反映在软件包列表中:

$ conda list --export > conda_list.txt

但是,我没有。因此,我改用了其他一些人建议的以下命令:

# get environment name by
$ conda-env list

# get list of all installed packages by (conda, pip, etc.,)
$ conda-env export -n <my-environment-name> > all_packages.yml
# if you haven't created any specific env, then just use 'root'

现在,我可以看到all-packages.yml文件中的所有软件包。

My which pip shows the following path:

$ which pip
/home/kmario23/anaconda3/bin/pip

So, whatever package I install using pip install <package-name> will have to be reflected in the list of packages when the list is exported using:

$ conda list --export > conda_list.txt

But, I don’t. So, instead I used the following command as suggested by several others:

# get environment name by
$ conda-env list

# get list of all installed packages by (conda, pip, etc.,)
$ conda-env export -n <my-environment-name> > all_packages.yml
# if you haven't created any specific env, then just use 'root'

Now, I can see all the packages in my all-packages.yml file.


回答 9

您可以先在conda环境中安装以下给定命令开始:

conda install pip

然后安装环境中所需的所有pip软件包。

安装所有conda和pip软件包以导出环境后,请使用:

conda env export -n <env-name> > environment.yml

这将在文件夹中创建所需的文件

You can start by installing the below given command in the conda environment:

conda install pip

Followed by installing all pip packages you need in the environment.

After installing all the conda and pip packages to export the environment use:

conda env export -n <env-name> > environment.yml

This will create the required file in the folder


删除Conda环境

问题:删除Conda环境

我想删除使用conda创建的特定环境。我该如何实现?假设我有一个活跃的testenv环境。我通过遵循文档尝试了:

$ conda env remove

CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again

然后我将其停用:

$ source deactivate

我尝试再次运行命令将其删除,但仍然出现相同的错误。这是怎么了?

I want to remove a certain environment created with conda. How can I achieve that? Let’s say I have an active testenv environment. I tried, by following documentation, with:

$ conda env remove

CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again

I then deactivate it:

$ source deactivate

I try running again the command to remove it and I still get the same error. What is going wrong here?


回答 0

您可能没有完全停用Conda环境-请记住,您需要在Conda中使用的命令是conda deactivate(对于旧版本,请使用source deactivate)。因此,在尝试之前,启动一个新的Shell并在其中激活环境可能是明智的。然后停用它。

您可以使用以下命令

conda env remove -n ENV_NAME

删除具有该名称的环境。(--name等于-n

请注意,您也可以将环境放置在要使用的任何位置,-p /path/to/env而不是-n ENV_NAME同时创建和删除环境(如果选择)。他们不具备住在你的畅达安装。

更新,2019年1月30日:从Conda 4.6起,该conda activate命令成为激活所有平台环境的新官方方式。更改在此Anaconda博客文章中进行了描述

You probably didn’t fully deactivate the Conda environment – remember, the command you need to use with Conda is conda deactivate (for older versions, use source deactivate). So it may be wise to start a new shell and activate the environment in that before you try. Then deactivate it.

You can use the command

conda env remove -n ENV_NAME

to remove the environment with that name. (--name is equivalent to -n)

Note that you can also place environments anywhere you want using -p /path/to/env instead of -n ENV_NAME when both creating and deleting environments, if you choose. They don’t have to live in your conda installation.

UPDATE, 30 Jan 2019: From Conda 4.6 onwards the conda activate command becomes the new official way to activate an environment across all platforms. The changes are described in this Anaconda blog post


回答 1

确保您的环境未处于活动状态后,键入:

$ conda env remove --name ENVIRONMENT

After making sure your environment is not active, type:

$ conda env remove --name ENVIRONMENT

回答 2

官方文档对我有用:

conda remove --name myenv --all

或者只是conda env remove --name myenv

要验证是否已删除环境,请在您的终端窗口或Anaconda Prompt中运行:

conda info --envs

显示的环境列表不应显示已删除的环境。

您的anaconda3环境文件夹可能会在anaconda3安装文件夹中列出已删除环境的空文件夹,例如:

/opt/anaconda3/envs

Official documentation way worked for me:

conda remove --name myenv --all

Or just conda env remove --name myenv.

To verify that the environment was removed, in your terminal window or an Anaconda Prompt, run:

conda info --envs

The environments list that displays should not show the removed environment.

You anaconda3 enviroments folder might list an empty folder of deleted environment in your anaconda3 installation folder, like:

/opt/anaconda3/envs

回答 3

总共有3种方法可以实现此目的。假设您有一个名为的环境myenv

  1. conda env remove --name myenv-n是的快捷方式--name

  2. conda remove --name myenv --all

  3. 直接删除env文件夹。(不建议)

    # list environments and their locations
    conda env list
    # or
    # conda info --envs
    
    # delete the folder listed
    rm -rf /Users/username/.local/share/conda/envs/myenv

如果您想删除环境而没有提示让您再次检查。使用的-y快捷方式--yes。(对于全局使用,请检查conda中的无提示提示

conda env remove -n myenv -y
conda remove -n myenv --all -y

参考资料

  • conda env --help
  • conda remove --help

There’re 3 ways to achieve this in total. Assuming you have a environment named myenv,

  1. conda env remove --name myenv, -n is shortcut for --name.

  2. conda remove --name myenv --all.

  3. Delete the env folder directly. (Not recommended)

    # list environments and their locations
    conda env list
    # or
    # conda info --envs
    
    # delete the folder listed
    rm -rf /Users/username/.local/share/conda/envs/myenv
    

If you wanna delete the environment without a prompt to let you check again. Use -y, shortcut for --yes. (For global use check silent prompt in conda)

conda env remove -n myenv -y
conda remove -n myenv --all -y

References

  • conda env --help
  • conda remove --help

回答 4

您可以尝试以下操作:打开anaconda命令提示符并键入

conda remove --name myenv --all

这将删除整个环境。

进一步阅读:docs.conda.io>管理环境

You may try the following: Open anaconda command prompt and type

conda remove --name myenv --all

This will remove the entire environment.

Further reading: docs.conda.io > Manage Environments


回答 5

首先,您必须先停用环境,然后再将其删除。您可以使用以下命令删除conda环境

假设您的环境名称为“ sample_env”,则可以使用删除此环境

source deactivate    
conda remove -n sample_env --all

‘–all’将用于删除所有依赖项

First you have to deactivate your environment before removing it. You can remove conda environment by using the following command

Suppose your environment name is “sample_env” , you can remove this environment by using

source deactivate    
conda remove -n sample_env --all

‘–all’ will be used to remove all the dependencies


回答 6

--prefix-p标志创建的环境必须用-p标志(not -n)删除。

例如: conda remove -p </filepath/myenvironment> --all,其中</filepath/myenvironment>用到环境的完整或相对路径代替。

Environments created with the --prefix or -p flag must be removed with the -p flag (not -n).

For example: conda remove -p </filepath/myenvironment> --all, in which </filepath/myenvironment> is substituted with a complete or relative path to the environment.


回答 7

我的环境名称是:test

conda remove -n test --all

My environment name is: test

conda remove -n test --all

回答 8

用于source deactivate在删除环境之前停用它,将ENV_NAME替换为您要删除的环境:

source deactivate
conda env remove -n ENV_NAME

Use source deactivate to deactivate the environment before removing it, replace ENV_NAME with the environment you wish to remove:

source deactivate
conda env remove -n ENV_NAME

回答 9

首先停用环境,然后返回基本环境。从基础上,您应该能够运行命令conda env remove -n <envname>。这会给你消息

Remove all packages in environment C:\Users\<username>\AppData\Local\Continuum\anaconda3\envs\{envname}:

First deactivate the environment and come back to the base environment. From the base, you should be able to run the command conda env remove -n <envname>. This will give you the message

Remove all packages in environment C:\Users\<username>\AppData\Local\Continuum\anaconda3\envs\{envname}:


回答 10

如果您在基地

(base) HP-Compaq-Elite-8300-CMT:~$ 

通过以下方式删除env_name

conda env remove -n env_name

如果您已经在env_name环境中:

(env_name) HP-Compaq-Elite-8300-CMT:~$ 

停用然后通过以下方式删除:

conda deactivate env_name

conda env remove -n env_name

if you are in base:

(base) HP-Compaq-Elite-8300-CMT:~$ 

remove env_name by:

conda env remove -n env_name

if you are already in env_name environment :

(env_name) HP-Compaq-Elite-8300-CMT:~$ 

deactivate then remove by :

conda deactivate env_name

conda env remove -n env_name

回答 11

这为我工作:

conda env remove --name tensorflow

This worked for me:

conda env remove --name tensorflow

回答 12

删除完整的conda环境:

康达删除–name YOUR_CONDA_ENV_NAME-全部

To remove complete conda environment :

conda remove --name YOUR_CONDA_ENV_NAME --all


回答 13

因为您只能停用活动环境,所以conda deactivate既不需要也不接受参数。错误消息在这里非常明确。

只需调用conda停用 https://github.com/conda/conda/issues/7296#issuecomment-389504269

Because you can only deactivate the active environment, so conda deactivate does not need nor accept arguments. The error message is very explicit here.

Just call conda deactivate https://github.com/conda/conda/issues/7296#issuecomment-389504269


使用Conda进行批量包装更新

问题:使用Conda进行批量包装更新

有没有一种方法(使用conda更新),我可以列出过时的软件包并选择或批量更新Anaconda中的软件包(兼容)?

单独更新软件包没有太大意义,因为有数百个软件包。

Is there a way (using conda update) that I can list outdated packages and select or bulk update (compatible) packages in Anaconda?

It doesn’t make much sense updating the packages individually as there are hundreds of them.


回答 0

你要conda update --all

conda search --outdated将显示过时的软件包并对其conda update --all进行更新(请注意,后者不会将您从Python 2更新到Python 3,但如果您使用Python 2,前者将显示Python已过时)。

You want conda update --all.

conda search --outdated will show outdated packages, and conda update --all will update them (note that the latter will not update you from Python 2 to Python 3, but the former will show Python as being outdated if you do use Python 2).


回答 1

在继续执行conda update --all命令之前,conda update conda如果很长时间没有更新conda,请先使用command更新它。它发生在我身上(Anaconda 64位上的Python 2.7.13)。

Before you proceed to conda update --all command, first update conda with conda update conda command if you haven’t update it for a long time. It happent to me (Python 2.7.13 on Anaconda 64 bits).


回答 2

Conda Package Manager几乎已准备好进行Beta测试,但直到Spyder 2.4(https://github.com/spyder-ide/spyder/wiki/Roadmap)发行后,才能完全集成。准备好进行测试后,我们会在邮件列表(https://groups.google.com/forum/#!forum/spyderlib)上发布一些内容。请务必订阅

干杯!

the Conda Package Manager is almost ready for beta testing, but it will not be fully integrated until the release of Spyder 2.4 (https://github.com/spyder-ide/spyder/wiki/Roadmap). As soon as we have it ready for testing we will post something on the mailing list (https://groups.google.com/forum/#!forum/spyderlib). Be sure to subscribe

Cheers!


回答 3

# list packages that can be updated
conda search --outdated

# update all packages prompted(by asking the user yes/no)
conda update --all

# update all packages unprompted
conda update --all -y
# list packages that can be updated
conda search --outdated

# update all packages prompted(by asking the user yes/no)
conda update --all

# update all packages unprompted
conda update --all -y

康达能否取代对virtualenv的需求?

问题:康达能否取代对virtualenv的需求?

我在安装SciPy时遇到了麻烦,最近发现了Conda,特别是在我正在开发的Heroku应用程序上。

使用Conda,您可以创建与virtualenv十分相似的环境。我的问题是:

  1. 如果我使用Conda,它将取代对virtualenv的需求吗?如果没有,如何将两者一起使用?是否在Conda中安装virtualenv或在virtualenv中安装Conda?
  2. 我还需要使用点子吗?如果是这样,我仍然可以在隔离的环境中使用pip安装软件包吗?

I recently discovered Conda after I was having trouble installing SciPy, specifically on a Heroku app that I am developing.

With Conda you create environments, very similar to what virtualenv does. My questions are:

  1. If I use Conda will it replace the need for virtualenv? If not, how do I use the two together? Do I install virtualenv in Conda, or Conda in virtualenv?
  2. Do I still need to use pip? If so, will I still be able to install packages with pip in an isolated environment?

回答 0

  1. 康达取代了virtualenv。我认为这更好。它不仅限于Python,还可以用于其他语言。以我的经验,它提供了更加流畅的体验,尤其是对于科学包装。我第一次在Mac上正确安装MayaVi是使用conda

  2. 您仍然可以使用pip。实际上,conda安装pip在每个新环境中。它知道有关pip安装的软件包的信息。

例如:

conda list

列出当前环境中所有已安装的软件包。Conda安装的软件包显示如下:

sphinx_rtd_theme          0.1.7                    py35_0    defaults

并通过安装的pip带有<pip>标记:

wxpython-common           3.0.0.0                   <pip>
  1. Conda replaces virtualenv. In my opinion it is better. It is not limited to Python but can be used for other languages too. In my experience it provides a much smoother experience, especially for scientific packages. The first time I got MayaVi properly installed on Mac was with conda.

  2. You can still use pip. In fact, conda installs pip in each new environment. It knows about pip-installed packages.

For example:

conda list

lists all installed packages in your current environment. Conda-installed packages show up like this:

sphinx_rtd_theme          0.1.7                    py35_0    defaults

and the ones installed via pip have the <pip> marker:

wxpython-common           3.0.0.0                   <pip>

回答 1

简短的答案是,您只需要conda。

  1. Conda在单个软件包中有效地结合了pip和virtualenv的功能,因此,如果您使用的是conda,则不需要virtualenv。

  2. 您会惊讶conda支持多少个软件包。如果还不够,可以在conda下使用pip。

这是到conda页面的链接,用于比较conda,pip和virtualenv:

https://docs.conda.io/projects/conda/zh-CN/latest/commands.html#conda-vs-pip-vs-virtualenv-commands

Short answer is, you only need conda.

  1. Conda effectively combines the functionality of pip and virtualenv in a single package, so you do not need virtualenv if you are using conda.

  2. You would be surprised how many packages conda supports. If it is not enough, you can use pip under conda.

Here is a link to the conda page comparing conda, pip and virtualenv:

https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands.


回答 2

虚拟环境和 pip

我会补充说,使用Anaconda可以轻松创建删除 conda环境。

> conda create --name <envname> python=<version> <optional dependencies>

> conda remove --name <envname> --all 

激活的环境中,通过conda或安装软件包pip

(envname)> conda install <package>

(envname)> pip install <package>

这些环境与conda的pip式软件包管理紧密相关,因此创建环境以及安装Python和非Python软件包都很简单。


朱皮特

此外,在环境中安装ipykernel在Jupyter笔记本的“内核”下拉菜单中会添加一个新列表,从而将可复制的环境扩展到笔记本。从Anaconda 4.1开始,添加了nbextensions,更轻松地为笔记本添加了扩展名。

可靠性

以我的经验,conda在安装大型库(例如numpy和)时更快,更可靠pandas。此外,如果您希望转移环境的保留状态,则可以通过共享克隆环境来实现。

Virtual Environments and pip

I will add that creating and removing conda environments is simple with Anaconda.

> conda create --name <envname> python=<version> <optional dependencies>

> conda remove --name <envname> --all 

In an activated environment, install packages via conda or pip:

(envname)> conda install <package>

(envname)> pip install <package>

These environments are strongly tied to conda’s pip-like package management, so it is simple to create environments and install both Python and non-Python packages.


Jupyter

In addition, installing ipykernel in an environment adds a new listing in the Kernels dropdown menu of Jupyter notebooks, extending reproducible environments to notebooks. As of Anaconda 4.1, nbextensions were added, adding extensions to notebooks more easily.

Reliability

In my experience, conda is faster and more reliable at installing large libraries such as numpy and pandas. Moreover, if you wish to transfer your the preserved state of an environment, you can do so by sharing or cloning an env.


回答 3

安装Conda将使您能够根据需要创建和删除python环境,从而为您提供与virtualenv相同的功能。

对于这两种发行版,您将能够创建一个隔离的文件系统树,在其中您可以根据需要安装和删除python软件包(可能是pip)。如果您想为不同的用例使用同一个库的不同版本,或者只想尝试进行一些发行并将其删除以节省磁盘空间,则可能会派上用场。

差异:

许可协议。虽然virtualenv已获得MIT最宽松的许可证,但Conda使用3条款BSD许可。

康达为您提供了自己的包装控制系统。这个程序包控制系统通常提供流行的非python软件的预编译版本(对于大多数流行的系统),这可以很容易地使某些机器学习程序包正常工作。也就是说,您不必为系统编译优化的C / C ++代码。虽然这对我们大多数人来说是一个很大的缓解,但它可能会影响此类库的性能。

与virtualenv不同,Conda至少在Linux系统上复制了一些系统库。该库可能不同步,从而导致程序行为不一致。

判决:

Conda很棒,应该是您开始机器学习之路的默认选择。它将为您节省一些时间,使他们无法使用gcc和许多软件包。但是,Conda并没有取代virtualenv。它引入了一些额外的复杂性,而这些复杂性可能并非总是需要的。它具有不同的许可。您可能要避免在分布式环境或HPC硬件上使用conda。

Installing Conda will enable you to create and remove python environments as you wish, therefore providing you with same functionality as virtualenv would.

In case of both distributions you would be able to create an isolated filesystem tree, where you can install and remove python packages (probably, with pip) as you wish. Which might come in handy if you want to have different versions of same library for different use cases or you just want to try some distribution and remove it afterwards conserving your disk space.

Differences:

License agreement. While virtualenv comes under most liberal MIT license, Conda uses 3 clause BSD license.

Conda provides you with their own package control system. This package control system often provides precompiled versions (for most popular systems) of popular non-python software, which can easy ones way getting some machine learning packages working. Namely you don’t have to compile optimized C/C++ code for you system. While it is a great relief for most of us, it might affect performance of such libraries.

Unlike virtualenv, Conda duplicating some system libraries at least on Linux system. This libraries can get out of sync leading to inconsistent behavior of your programs.

Verdict:

Conda is great and should be your default choice while starting your way with machine learning. It will save you some time messing with gcc and numerous packages. Yet, Conda does not replace virtualenv. It introduces some additional complexity which might not always be desired. It comes under different license. You might want to avoid using conda on a distributed environments or on HPC hardware.


回答 4

我同时使用和(截至2020年1月)它们具有一些肤浅的差异,因此适合我的不同用法。通过默认康达更喜欢在一个中央位置来管理你的环境的列表,而使得的virtualenv在当前目录中的文件夹。前者(集中式)在您进行机器学习时才有意义,例如,您有几个广泛的环境可用于许多项目,并且想从任何地方跳入其中。如果您正在做一些一次性项目,这些项目具有完全不同的lib需求集,而lib需求集实际上更多地属于项目本身,则后者(每个项目文件夹)才有意义。

Conda创建的空环境约为122MB,而virtualenv约为12MB,因此,这是您可能不希望将Conda环境分散在各处的另一个原因。

最后,表明Conda偏爱其集中式env的另一个表面现象是(同样,默认情况下),如果您确实在自己的项目文件夹中创建了一个Conda env并激活它,则出现在外壳中的名称前缀是(太长)绝对值文件夹的路径。您可以通过给它命名来解决该问题,但是virtualenv默认情况下做对了。

我希望随着两个程序包管理者争夺霸主地位,此信息会迅速过时,但这是今天的权衡:)

I use both and (as of Jan, 2020) they have some superficial differences that lend themselves to different usages for me. By default Conda prefers to manage a list of environments for you in a central location, whereas virtualenv makes a folder in the current directory. The former (centralized) makes sense if you are e.g. doing machine learning and just have a couple of broad environments that you use across many projects and want to jump into them from anywhere. The latter (per project folder) makes sense if you are doing little one-off projects that have completely different sets of lib requirements that really belong more to the project itself.

The empty environment that Conda creates is about 122MB whereas the virtualenv’s is about 12MB, so that’s another reason you may prefer not to scatter Conda environments around everywhere.

Finally, another superficial indication that Conda prefers its centralized envs is that (again, by default) if you do create a Conda env in your own project folder and activate it the name prefix that appears in your shell is the (way too long) absolute path to the folder. You can fix that by giving it a name, but virtualenv does the right thing by default.

I expect this info to become stale rapidly as the two package managers vie for dominance, but these are the trade-offs as of today :)


回答 5

Pipenv是另一个新的选择,也是我当前首选的启动和运行环境的方法。

目前,它是Python.org官方推荐的Python打包工具

Another new option and my current preferred method of getting an environment up and running is Pipenv

It is currently the officially recommended Python packaging tool from Python.org


回答 6

是的,conda它比容易安装得多virtualenv,并且几乎可以替代后者。

Yes, conda is a lot easier to install than virtualenv, and pretty much replaces the latter.


回答 7

我在公司工作,在几台没有管理员权限的计算机的防火墙后面

以我有限的python使用经验(两年),我遇到了几个库(JayDeBeApi,sasl),这些库通过pip安装时会抛出C ++依赖项错误错误:需要Microsoft Visual C ++ 14.0。使用“ Microsoft Visual C ++生成工具”获得它:http : //landinghub.visualstudio.com/visual-cpp-build-tools

这些用conda安装得很好,因此从那以后,我开始使用conda env。但是要阻止conda从c.programfiles里面安装依赖项并不容易,因为我没有写权限。

I work in corporate, behind several firewall with machine on which I have no admin acces

In my limited experience with python (2 years) i have come across few libraries (JayDeBeApi,sasl) which when installing via pip threw C++ dependency errors error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools

these installed fine with conda, hence since those days i started working with conda env. however it isnt easy to stop conda from installing dependency inside c.programfiles where i dont have write access.


如何更新Anaconda?

问题:如何更新Anaconda?

我的计算机上安装了Anaconda,我想对其进行更新。在Navigator中,我可以看到有几个单独的软件包可以更新,但anaconda有时也有版本号,有时显示custom。我该如何进行?

I have Anaconda installed on my computer and I’d like to update it. In Navigator I can see that there are several individual packages that can be updated, but also an anaconda package that sometimes has a version number and sometimes says custom. How do I proceed?


回答 0

95%的人实际想要什么

在大多数情况下,当您说要更新Anaconda时,要执行的命令是执行以下命令:

conda update --all

(但是,这应该preceeded通过conda update -n root conda让你拥有最新conda安装的版本)

这会将当前环境中的所有软件包更新为最新版本-较小的字样是它可能会使用某些版本的旧软件包以满足相关性约束(通常不需要这样做,并且在必要时可以打包方案求解器将尽最大努力将影响降到最低)。

这需要从命令行执行,并且到达那里的最佳方法是从Anaconda Navigator,然后单击“环境”选项卡,然后单击root环境旁边的三角形,选择“打开终端”:

此操作将仅更新一个选定的环境(在这种情况下为root环境)。如果您要更新其他环境,则可以重复上述过程,但请先单击该环境。选择该选项后,右侧会有一个三角形标记(请参见上图,第3步)。或从命令行中,您可以提供环境名称(-n envname)或路径(-p /path/to/env),例如,dspyr从上面的屏幕截图中更新您的环境:

conda update -n dspyr --all

更新单个软件包

如果您只对更新单个软件包感兴趣,则只需在Navigator中单击蓝色箭头或蓝色版本号,例如在上面的屏幕截图中astroidastropy在上面的屏幕截图中,这将标记这些软件包以进行升级。完成后,您需要单击“应用”按钮:

或从命令行:

conda update astroid astropy

仅更新标准Anaconda发行版中的软件包

如果您不关心软件包的版本,而只是想要“标准Anaconda发行版中所有软件包的最新集合,只要它们可以一起使用”,那么您应该了解一下这个要点

为什么更新Anaconda软件包几乎总是一个坏主意

在大多数情况下,更新软件包列表中的Anaconda软件包将产生令人惊讶的结果:您实际上可以降级许多软件包(实际上,如果将版本表示为,则可能会降级custom)。上面的要点提供了详细信息。

利用conda环境

您的root环境可能不是尝试管理一组确切软件包的好地方:它将是一个动态工作空间,其中安装了新软件包并随机更新了软件包。如果您需要一组确切的软件包,请创建一个conda环境来保存它们。多亏了conda软件包缓存和文件链接的使用方式,通常i)快速,并且ii)占用很少的额外磁盘空间。例如

conda create -n myspecialenv -c bioconda -c conda-forge python=3.5 pandas beautifulsoup seaborn nltk

畅达文档有更多的细节和例子。

pip,PyPI和setuptools?

这些都无法帮助更新通过PyPI从PyPI pip安装的软件包或使用来安装的任何软件包python setup.py installconda list会为您提供有关环境中基于pip的Python软件包的一些提示,但不会对其进行任何特殊更新。

Anaconda或Anaconda Enterprise的商业用途

它几乎是完全相同的故事,除了root如果环境是由其他人安装的(例如/opt/anaconda/latest),您可能无法更新。如果您无法更新正在使用的环境,则应该能够克隆然后更新:

conda create -n myenv --clone root
conda update -n myenv --all

root is the old (pre-conda 4.4) name for the main environment; after conda 4.4, it was renamed to be base. source

What 95% of people actually want

In most cases what you want to do when you say that you want to update Anaconda is to execute the command:

conda update --all

(But this should be preceeded by conda update -n base conda so you have the latest conda version installed)

This will update all packages in the current environment to the latest version — with the small print being that it may use an older version of some packages in order to satisfy dependency constraints (often this won’t be necessary and when it is necessary the package plan solver will do its best to minimize the impact).

This needs to be executed from the command line, and the best way to get there is from Anaconda Navigator, then the “Environments” tab, then click on the triangle beside the base environment, selecting “Open Terminal”:

This operation will only update the one selected environment (in this case, the base environment). If you have other environments you’d like to update you can repeat the process above, but first click on the environment. When it is selected there is a triangular marker on the right (see image above, step 3). Or from the command line you can provide the environment name (-n envname) or path (-p /path/to/env), for example to update your dspyr environment from the screenshot above:

conda update -n dspyr --all

Update individual packages

If you are only interested in updating an individual package then simply click on the blue arrow or blue version number in Navigator, e.g. for astroid or astropy in the screenshot above, and this will tag those packages for an upgrade. When you are done you need to click the “Apply” button:

Or from the command line:

conda update astroid astropy

Updating just the packages in the standard Anaconda Distribution

If you don’t care about package versions and just want “the latest set of all packages in the standard Anaconda Distribution, so long as they work together”, then you should take a look at this gist.

Why updating the Anaconda package is almost always a bad idea

In most cases updating the Anaconda package in the package list will have a surprising result: you may actually downgrade many packages (in fact, this is likely if it indicates the version as custom). The gist above provides details.

Leverage conda environments

Your base environment is probably not a good place to try and manage an exact set of packages: it is going to be a dynamic working space with new packages installed and packages randomly updated. If you need an exact set of packages then create a conda environment to hold them. Thanks to the conda package cache and the way file linking is used doing this is typically i) fast and ii) consumes very little additional disk space. E.g.

conda create -n myspecialenv -c bioconda -c conda-forge python=3.5 pandas beautifulsoup seaborn nltk

The conda documentation has more details and examples.

pip, PyPI, and setuptools?

None of this is going to help with updating packages that have been installed from PyPI via pip or any packages installed using python setup.py install. conda list will give you some hints about the pip-based Python packages you have in an environment, but it won’t do anything special to update them.

Commercial use of Anaconda or Anaconda Enterprise

It is pretty much exactly the same story, with the exception that you may not be able to update the base environment if it was installed by someone else (say to /opt/anaconda/latest). If you’re not able to update the environments you are using you should be able to clone and then update:

conda create -n myenv --clone base
conda update -n myenv --all

回答 1

如果您尝试将Anaconda版本更新为新版本,则会注意到运行新安装程序无效,因为它抱怨安装目录为非空。

因此,您应该使用conda进行升级,如官方文档所述

conda update conda
conda update anaconda


在Windows中,如果进行了“针对所有用户”安装,则可能需要从具有管理员权限的Anaconda提示符下运行。

这样可以防止错误:

错误conda.core.link:_execute(502):卸载软件包“ defaults :: conda-4.5.4-py36_0”时发生错误。PermissionError(13,’访问被拒绝’)

If you are trying to update your Anaconda version to a new one, you’ll notice that running the new installer wouldn’t work, as it complains the installation directory is non-empty.

So you should use conda to upgrade as detailed by the official docs:

conda update conda
conda update anaconda


In Windows, if you made a “for all users” installation, it might be necessary to run from an Anaconda prompt with Administrator privileges.

This prevents the error:

ERROR conda.core.link:_execute(502): An error occurred while uninstalling package ‘defaults::conda-4.5.4-py36_0’. PermissionError(13, ‘Access is denied’)


回答 2

打开“命令或conda提示符”并运行:

conda update conda
conda update anaconda

最好两次运行两个命令(一个接一个),以确保所有基本文件都已更新。

这应该使您重新使用最新的“发行版”,其中包含Continuum的人员选择的软件包以使其协同工作。

如果要运行每个软件包的最新版本(这可能导致不稳定的环境):

conda update --all 

希望这可以帮助。

资料来源:

Open “command or conda prompt” and run:

conda update conda
conda update anaconda

It’s a good idea to run both command twice (one after the other) to be sure that all the basic files are updated.

This should put you back on the latest ‘releases’, which contains packages that are selected by the people at Continuum to work well together.

If you want the last version of each package run (this can lead to an unstable environment):

conda update --all 

Hope this helps.

Sources:


回答 3

如果您无法从例如3.3.x升级到4.x(conda更新conda“无法正常工作”以获取下一个版本),则可以尝试像这样更具体:

conda install conda=4.0 (or conda install anaconda=4.0)

https://www.anaconda.com/blog/developer-blog/anaconda-4-release/

您应该知道自己的操作,因为conda可能会由于强制安装而损坏。如果您想获得更大的灵活性/安全性,可以使用pkg-manager,例如nix(-pkgs)[with nix-shell] / NixOS。

If you have trouble to get e.g. from 3.3.x to 4.x (conda update conda “does not work” to get to the next version) than try it more specific like so:

conda install conda=4.0 (or conda install anaconda=4.0)

https://www.anaconda.com/blog/developer-blog/anaconda-4-release/

You should know what you do, because conda could break due to the forced installation. If you would like to get more flexibility/security you could use pkg-manager like nix(-pkgs) [with nix-shell] / NixOS.


回答 4

这是Anaconda官方文档建议的内容:

conda update conda 
conda update anaconda=2020.02

如果第二行抛出错误(文档中有错字?),则可以在这里工作:

conda install anaconda=2020.02

(您可以在此处找到所有版本说明符)

该命令将更新为Anaconda meta-package的特定版本。

是95%Anaconda用户想要的东西。只需升级到最新版本的Anaconda元软件包(放到一起并由Anaconda发行商进行测试),而不必关心单个软件包的更新状态(由发行conda update --all)。

This is what the official Anaconda documentation recommends:

conda update conda
conda update anaconda=2020.07

If the second line throws an error (typo in the documentation?) this worked here:

conda install anaconda=2020.07

(You can find all version specifier here.)

The command will update to a specific release of the Anaconda meta-package.

This is, IMHO, what 95% of Anaconda users want. Simply upgrading to the latest version of the Anaconda meta-package (put together and tested by the Anaconda Distributors) and not caring about the update status of individual packages (which would be issued by conda update --all).


回答 5

这是最佳做法(以我的拙劣经验来说)。选择这四个软件包还将把所有其他依赖项更新为适当的版本,这将帮助您保持环境的一致性。后者是其他人在较早回应中表达的普遍问题。该解决方案不需要终端。

Here’s the best practice (in my humble experience). Selecting these four packages will also update all other dependencies to the appropriate versions that will help you keep your environment consistent. The latter is a common problem others have expressed in earlier responses. This solution doesn’t need the terminal.


回答 6

在基本模式下打开Anaconda cmd:

然后使用conda update conda更新Anaconda

然后您可以使用conda update –all来更新Anaconda的所有要求

conda update conda  
conda update --all  

Open Anaconda cmd in base mode:

Then use conda update conda to update Anaconda.

You can then use conda update –all to update all the requirements for Anaconda:

conda update conda
conda update --all

回答 7

在Mac上,打开终端并运行以下2条命令。

conda update conda
conda update anaconda

确保多次运行每个命令以更新到当前版本。

On Mac, open a terminal and run the following two commands.

conda update conda
conda update anaconda

Make sure to run each command multiple times to update to the current version.


回答 8

我正在使用Windows10。以下更新所有内容,并安装了一些新软件包,包括python更新(对我来说是3.7.3)。

在外壳上,尝试以下操作(请确保更改Anaconda3 Data的安装位置)。更新所有内容需要一些时间。

conda update --prefix X:\XXXXData\Anaconda3 anaconda

I’m using Windows 10. The following updates everything and also installs some new packages, including a Python update (for me it was 3.7.3).

At the shell, try the following (be sure to change where your Anaconda 3 Data is installed). It takes some time to update everything.

conda update --prefix X:\XXXXData\Anaconda3 anaconda

回答 9

要将安装的版本更新为最新版本(例如2019.07),请运行

conda install anaconda=2019.07

在大多数情况下,此方法可以满足您的需求并避免依赖性问题

To update your installed version to the latest version, say 2019.07, run:

conda install anaconda=2019.07

In most cases, this method can meet your needs and avoid dependency problems.


回答 10

conda create -n py37 -c anaconda anaconda=5.3.1
conda env export -n py37 --file env.yaml

在C:\ Windows \ System32中找到env.yaml并以管理员身份运行cmd

conda env update -n root -f env.yaml  

然后就可以了!

Use:

conda create -n py37 -c anaconda anaconda=5.3.1
conda env export -n py37 --file env.yaml

Locate the env.yaml file in C:\Windows\System32 and run the cmd as administrator:

conda env update -n root -f env.yaml

Then it works!


回答 11

这只能更新python:

conda update python

This can update the Python instance only:

conda update python

pip和conda有什么区别?

问题:pip和conda有什么区别?

我知道pip是python软件包的软件包管理器。但是,我看到IPython网站conda上的安装用于安装IPython。

我可以pip用来安装IPython吗?conda我已经拥有了为什么还要用作另一个python软件包管理器pip

pip和之间有什么区别conda

I know pip is a package manager for python packages. However, I saw the installation on IPython’s website use conda to install IPython.

Can I use pip to install IPython? Why should I use conda as another python package manager when I already have pip?

What is the difference between pip and conda?


回答 0

引用来自Conda博客

参与python世界已经很长时间了,我们都知道pip,easy_install和virtualenv,但是这些工具不能满足我们所有的特定要求。主要问题是它们专注于Python,而忽略了非Python库依赖项,例如HDF5,MKL,LLVM等,它们的源代码中没有setup.py,也没有将文件安装到Python的站点中-packages目录。

因此,Conda是一种包装工具和安装程序,旨在做更多的事情pip。处理Python包之外的库依赖关系以及Python包本身。Conda也像创建虚拟环境一样virtualenv

因此,也许应该将Conda与Buildout进行比较,后者是另一个可以让您处理Python和非Python安装任务的工具。

由于Conda引入了新的包装格式,因此您不能pip与Conda互换使用。 pip无法安装Conda软件包格式。您可以使用并排的两个工具侧(通过安装pipconda install pip),但他们不具备互操作性无论是。

自编写此答案以来,Anaconda 理解Conda和Pip发布了新页面,该页面也与此相呼应:

这凸显了conda和pip之间的关键区别。Pip安装Python软件包,而conda安装软件包,其中可能包含以任何语言编写的软件。例如,在使用pip之前,必须通过系统软件包管理器或下载并运行安装程序来安装Python解释器。另一方面,Conda可以直接安装Python软件包以及Python解释器。

并进一步

有时需要一个软件包,该软件包不是conda软件包,但在PyPI上可用,可以与pip一起安装。在这些情况下,尝试同时使用conda和pip是有意义的。

Quoting from the Conda blog:

Having been involved in the python world for so long, we are all aware of pip, easy_install, and virtualenv, but these tools did not meet all of our specific requirements. The main problem is that they are focused around Python, neglecting non-Python library dependencies, such as HDF5, MKL, LLVM, etc., which do not have a setup.py in their source code and also do not install files into Python’s site-packages directory.

So Conda is a packaging tool and installer that aims to do more than what pip does; handle library dependencies outside of the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenv does.

As such, Conda should be compared to Buildout perhaps, another tool that lets you handle both Python and non-Python installation tasks.

Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side (by installing pip with conda install pip) but they do not interoperate either.

Since writing this answer, Anaconda has published a new page on Understanding Conda and Pip, which echoes this as well:

This highlights a key difference between conda and pip. Pip installs Python packages whereas conda installs packages which may contain software written in any language. For example, before using pip, a Python interpreter must be installed via a system package manager or by downloading and running an installer. Conda on the other hand can install Python packages as well as the Python interpreter directly.

and further on

Occasionally a package is needed which is not available as a conda package but is available on PyPI and can be installed with pip. In these cases, it makes sense to try to use both conda and pip.


回答 1

这是一个简短的摘要:

点子

  • 仅Python软件包。
  • 从源代码编译所有内容。编辑:pip现在会安装二进制车轮(如果可用)。
  • 受核心Python社区的祝福(即Python 3.4+包含自动引导pip的代码)。

康达

  • 不可知的Python。现有软件包的主要焦点是用于Python,的确Conda本身是用Python编写的,但是您也可以拥有用于C库,R软件包或其他任何东西的Conda软件包。
  • 安装二进制文件。有一个名为的工具conda build可以从源代码构建软件包,但conda install它本身可以从已构建的Conda软件包安装东西。
  • 外部。Conda是Anaconda的软件包管理器,它是Continuum Analytics提供的Python发行版,但也可以在Anaconda之外使用。您可以通过pip安装将其与现有的Python安装配合使用(尽管除非您有充分的理由使用现有的安装,否则不建议这样做)。

在两种情况下:

  • 用Python编写
  • 开源(Conda是BSD,pip是MIT)

实际上,Conda的前两个要点是使许多包装优于点子的原因。由于pip是从源代码安装的,因此如果您无法编译源代码,则可能会很麻烦地安装东西(在Windows上尤其如此,但在Linux上,如果软件包中包含一些困难的C或FORTRAN库,甚至可能也是这样。依赖项)。Conda从二进制安装,这意味着某人(例如Continuum)已经完成了编译软件包的艰苦工作,因此安装很容易。

如果您对构建自己的软件包感兴趣,也有一些区别。例如,pip是建立在setuptools之上的,而Conda使用自己的格式,这种格式具有一些优点(例如,静态的,Python不可知的)。

Here is a short rundown:

pip

  • Python packages only.
  • Compiles everything from source. EDIT: pip now installs binary wheels, if they are available.
  • Blessed by the core Python community (i.e., Python 3.4+ includes code that automatically bootstraps pip).

conda

  • Python agnostic. The main focus of existing packages are for Python, and indeed Conda itself is written in Python, but you can also have Conda packages for C libraries, or R packages, or really anything.
  • Installs binaries. There is a tool called conda build that builds packages from source, but conda install itself installs things from already built Conda packages.
  • External. Conda is the package manager of Anaconda, the Python distribution provided by Continuum Analytics, but it can be used outside of Anaconda too. You can use it with an existing Python installation by pip installing it (though this is not recommended unless you have a good reason to use an existing installation).

In both cases:

  • Written in Python
  • Open source (Conda is BSD and pip is MIT)

The first two bullet points of Conda are really what make it advantageous over pip for many packages. Since pip installs from source, it can be painful to install things with it if you are unable to compile the source code (this is especially true on Windows, but it can even be true on Linux if the packages have some difficult C or FORTRAN library dependencies). Conda installs from binary, meaning that someone (e.g., Continuum) has already done the hard work of compiling the package, and so the installation is easy.

There are also some differences if you are interested in building your own packages. For instance, pip is built on top of setuptools, whereas Conda uses its own format, which has some advantages (like being static, and again, Python agnostic).


回答 2

其他答案对这些细节给出了合理的描述,但我想强调一些高级要点。

pip是一个软件包管理器,可简化python软件包的安装,升级和卸载。它还适用于虚拟python环境。

conda是任何软件(安装,升级和卸载)的软件包管理器。它还适用于虚拟系统环境。

conda设计的目标之一是促进用户所需的整个软件堆栈的软件包管理,其中一个或多个python版本可能只是其中的一小部分。这包括低级库(例如线性代数),编译器(例如Windows上的mingw),编辑器,版本控制工具(例如Hg和Git)或其他需要分发和管理的内容

对于版本管理,pip允许您在多个python环境之间切换和管理。

Conda允许您在多个通用环境之间进行切换和管理,在多个通用环境中,其他多个版本的版本号可能会有所不同,例如C库,编译器,测试套件或数据库引擎等。

Conda不是以Windows为中心的,但是在Windows上,当需要安装和管理需要编译的复杂科学软件包时,它是目前可用的高级解决方案。

当我想到尝试通过Windows上的pip编译许多这些软件包或pip install在需要编译时调试失败的会话时浪费了多少时间时,我想哭。

最后,Continuum Analytics还托管(免费)binstar.org(现在称为anaconda.org),以允许常规软件包开发人员创建自己的自定义(内置!)软件堆栈,包用户可以conda install从中使用它们。

The other answers give a fair description of the details, but I want to highlight some high-level points.

pip is a package manager that facilitates installation, upgrade, and uninstallation of python packages. It also works with virtual python environments.

conda is a package manager for any software (installation, upgrade and uninstallation). It also works with virtual system environments.

One of the goals with the design of conda is to facilitate package management for the entire software stack required by users, of which one or more python versions may only be a small part. This includes low-level libraries, such as linear algebra, compilers, such as mingw on Windows, editors, version control tools like Hg and Git, or whatever else requires distribution and management.

For version management, pip allows you to switch between and manage multiple python environments.

Conda allows you to switch between and manage multiple general purpose environments across which multiple other things can vary in version number, like C-libraries, or compilers, or test-suites, or database engines and so on.

Conda is not Windows-centric, but on Windows it is by far the superior solution currently available when complex scientific packages requiring compilation are required to be installed and managed.

I want to weep when I think of how much time I have lost trying to compile many of these packages via pip on Windows, or debug failed pip install sessions when compilation was required.

As a final point, Continuum Analytics also hosts (free) binstar.org (now called anaconda.org) to allow regular package developers to create their own custom (built!) software stacks that their package-users will be able to conda install from.


回答 3

不要再让您感到困惑了,但是您也可以在conda环境中使用pip,这可以验证上面的一般管理员和python特定管理员的评论。

conda install -n testenv pip
source activate testenv
pip <pip command>

您还可以将pip添加到任何环境的默认程序包中,因此每次都会显示pip,因此您不必遵循上述代码段。

Not to confuse you further, but you can also use pip within your conda environment, which validates the general vs. python specific managers comments above.

conda install -n testenv pip
source activate testenv
pip <pip command>

you can also add pip to default packages of any environment so it is present each time so you don’t have to follow the above snippet.


回答 4

引用康达在Continuum网站上发表的关于数据科学的文章:

康达vs点

Python程序员可能很熟悉pip从PyPI下载软件包并管理他们的要求。尽管conda和pip都是程序包管理器,但它们却大不相同:

  • Pip是特定于Python软件包的,而conda是与语言无关的,这意味着我们可以使用conda管理任何语言的软件包。
  • Conda本机创建与语言无关的环境,而pip依靠virtualenv仅管理Python环境尽管建议始终使用conda软件包,但conda也包含pip,因此您不必在这两者之间进行选择。例如,要安装没有conda软件包但可通过pip获得的python软件包,请运行,例如:
conda install pip
pip install gensim

Quote from Conda for Data Science article onto Continuum’s website:

Conda vs pip

Python programmers are probably familiar with pip to download packages from PyPI and manage their requirements. Although, both conda and pip are package managers, they are very different:

  • Pip is specific for Python packages and conda is language-agnostic, which means we can use conda to manage packages from any language Pip compiles from source and conda installs binaries, removing the burden of compilation
  • Conda creates language-agnostic environments natively whereas pip relies on virtualenv to manage only Python environments Though it is recommended to always use conda packages, conda also includes pip, so you don’t have to choose between the two. For example, to install a python package that does not have a conda package, but is available through pip, just run, for example:
conda install pip
pip install gensim

回答 5

引用《Conda:神话与误解》(全面描述):

误解3:Conda和Pip是直接竞争对手

现实:Conda和pip服务于不同的目的,仅直接竞争一小部分任务:即在隔离的环境中安装Python软件包。

皮普,代表P IP nstalls P ackages,是Python的官方认可的包管理器,并且是最常用的在其上安装Python包索引(PyPI中)发布的数据包。pip和PyPI均受Python Packaging Authority(PyPA)管辖和支持。

简而言之,pip是Python软件包的通用管理器。conda是与语言无关的跨平台环境管理器。对于用户而言,最明显的区别可能是:pip在任何环境中安装python软件包;conda在conda环境中安装任何软件包。如果您要做的只是在隔离的环境中安装Python软件包,则conda和pip + virtualenv通常是可互换的,从而在依赖项处理和软件包可用性方面取得了一些差异。隔离环境是指conda-env或virtualenv,您可以在其中安装软件包而无需修改系统Python安装。

即使抛开神话#2,如果我们只关注Python软件包的安装,conda和pip也可以为不同的受众和不同的目的服务。例如,如果要管理现有系统Python安装中的Python软件包,conda不能为您提供帮助:根据设计,它只能在conda环境中安装软件包。例如,如果您想使用许多依赖于外部依赖关系的Python包(NumPy,SciPy和Matplotlib是常见的示例),而以有意义的方式跟踪这些依赖关系时,pip并不能帮助您:通过设计,它仅管理Python软件包。

Conda和pip不是竞争对手,而是针对不同用户群和使用方式的工具。

Quoting from Conda: Myths and Misconceptions (a comprehensive description):

Myth #3: Conda and pip are direct competitors

Reality: Conda and pip serve different purposes, and only directly compete in a small subset of tasks: namely installing Python packages in isolated environments.

Pip, which stands for Pip Installs Packages, is Python’s officially-sanctioned package manager, and is most commonly used to install packages published on the Python Package Index (PyPI). Both pip and PyPI are governed and supported by the Python Packaging Authority (PyPA).

In short, pip is a general-purpose manager for Python packages; conda is a language-agnostic cross-platform environment manager. For the user, the most salient distinction is probably this: pip installs python packages within any environment; conda installs any package within conda environments. If all you are doing is installing Python packages within an isolated environment, conda and pip+virtualenv are mostly interchangeable, modulo some difference in dependency handling and package availability. By isolated environment I mean a conda-env or virtualenv, in which you can install packages without modifying your system Python installation.

Even setting aside Myth #2, if we focus on just installation of Python packages, conda and pip serve different audiences and different purposes. If you want to, say, manage Python packages within an existing system Python installation, conda can’t help you: by design, it can only install packages within conda environments. If you want to, say, work with the many Python packages which rely on external dependencies (NumPy, SciPy, and Matplotlib are common examples), while tracking those dependencies in a meaningful way, pip can’t help you: by design, it manages Python packages and only Python packages.

Conda and pip are not competitors, but rather tools focused on different groups of users and patterns of use.


回答 6

对于WINDOWS用户

最近,“标准”包装工具的状况正在改善:

  • 截至9月,在pypi本身上,有48%的车轮包装。2015年11月11日(高于2015年5月的38%和2014年9月的24%),

  • 现在,最新的python 2.7.9支持开箱即用的wheel格式,

“标准” +“调整”包装工具的状况也在改善:

  • 您可以在http://www.lfd.uci.edu/~gohlke/pythonlibs上找到几乎所有关于转轮格式的科学软件包,

  • mingwpy项目可能有一天为Windows用户带来一个“编译”包,允许在需要时从源代码安装所有内容。

“康达”包装对于所服务的市场而言仍然更好,并强调了“标准” 应该改进的地方。

(同样,在标准车轮系统和conda系统中,或者在扩展方面,依赖规范的多方面努力不是很Python,如果所有这些打包的“核心”技术都可以通过某种PEP收敛,那就太好了)

For WINDOWS users

“standard” packaging tools situation is improving recently:

  • on pypi itself, there are now 48% of wheel packages as of sept. 11th 2015 (up from 38% in may 2015 , 24% in sept. 2014),

  • the wheel format is now supported out-of-the-box per latest python 2.7.9,

“standard”+”tweaks” packaging tools situation is improving also:

  • you can find nearly all scientific packages on wheel format at http://www.lfd.uci.edu/~gohlke/pythonlibs,

  • the mingwpy project may bring one day a ‘compilation’ package to windows users, allowing to install everything from source when needed.

“Conda” packaging remains better for the market it serves, and highlights areas where the “standard” should improve.

(also, the dependency specification multiple-effort, in standard wheel system and in conda system, or buildout, is not very pythonic, it would be nice if all these packaging ‘core’ techniques could converge, via a sort of PEP)


回答 7

pip 是包裹经理。

conda 既是包管理器又是环境管理器。

详情:

参考文献

pip is a package manager.

conda is both a package manager and an environment manager.

Detail:

References


回答 8

我可以使用pip安装iPython吗?

当然,两者(第一种方法在页面上)

pip install ipython

和(第三种方法,第二种是conda

您可以从GitHub或PyPI手动下载IPython。要安装这些版本之一,请解压缩它并使用终端从顶级源目录运行以下命令:

pip install .

官方推荐的安装方法

当我已经有了pip时,为什么还要使用conda作为另一个python软件包管理器?

这里所说:

如果您需要一个特定的软件包,也许仅用于一个项目,或者需要与其他人共享该项目,那么conda似乎更合适。

康达(YMMV)超过点

  • 使用非Python工具的项目
  • 与同事分享
  • 在版本之间切换
  • 在具有不同库版本的项目之间切换

pip和conda有什么区别?

其他所有人对此都有广泛的回答。

Can I use pip to install iPython?

Sure, both (first approach on page)

pip install ipython

and (third approach, second is conda)

You can manually download IPython from GitHub or PyPI. To install one of these versions, unpack it and run the following from the top-level source directory using the Terminal:

pip install .

are officially recommended ways to install.

Why should I use conda as another python package manager when I already have pip?

As said here:

If you need a specific package, maybe only for one project, or if you need to share the project with someone else, conda seems more appropriate.

Conda surpasses pip in (YMMV)

  • projects that use non-python tools
  • sharing with colleagues
  • switching between versions
  • switching between projects with different library versions

What is the difference between pip and conda?

That is extensively answered by everyone else.


回答 9

pip 仅适用于Python

conda仅适用于Anaconda +其他科学软件包,例如R依赖等。并非每个人都需要Python附带的Anaconda。Anaconda主要适合那些进行机器学习/深度学习等的人。Casual Python开发人员不会在他的笔记本电脑上运行Anaconda。

pip is for Python only

conda is only for Anaconda + other scientific packages like R dependencies etc. NOT everyone needs Anaconda that already comes with Python. Anaconda is mostly for those who do Machine learning/deep learning etc. Casual Python dev won’t run Anaconda on his laptop.


回答 10

我可能已经发现了另一小的区别。我在python环境下/usr而不是在/home任何环境下。为了安装它,我将不得不使用sudo install pip。对我来说,不想要的副作用sudo install pip是比被广泛报道的其他地方略有不同:这样做之后,我还得跑pythonsudo以进口任何的sudo-installed包。我放弃了这一点,最终发现我可以sudo conda将软件包安装到一个环境中/usr,然后在该环境下可以正常导入而不需要sudo获得许可python。我什sudo conda至习惯于修复损坏的东西,pip而不是使用sudo pip uninstall pipor sudo pip --upgrade install pip

I may have found one further difference of a minor nature. I have my python environments under /usr rather than /home or whatever. In order to install to it, I would have to use sudo install pip. For me, the undesired side effect of sudo install pip was slightly different than what are widely reported elsewhere: after doing so, I had to run python with sudo in order to import any of the sudo-installed packages. I gave up on that and eventually found I could use sudo conda to install packages to an environment under /usr which then imported normally without needing sudo permission for python. I even used sudo conda to fix a broken pip rather than using sudo pip uninstall pip or sudo pip --upgrade install pip.