Python 离线时如何安装 conda 环境?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31729731/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:28:56  来源:igfitidea点击:

How can I install a conda environment when offline?

pythonanacondaconda

提问by WalkingRandomly

I would like to create a conda environment on a machine that has no network connection. What I've done so far is:

我想在没有网络连接的机器上创建一个 conda 环境。到目前为止我所做的是:

On a machine that is connected to the internet:

在连接到互联网的机器上:

conda create -n python3 python=3.4 anaconda

Conda archived all of the relevant packages into \Anaconda\pkgs. I put these into a separate folder and moved it to the machine with no network connection. The folder has the path PATHTO\Anaconda_py3\win-64

Conda 将所有相关包归档到\Anaconda\pkgs. 我把它们放在一个单独的文件夹中,然后将它移到没有网络连接的机器上。文件夹有路径PATHTO\Anaconda_py3\win-64

I tried

我试过

conda create -n python=3.4 anaconda --offline --channel PATHTO\Anaconda_py3

This gives the error message

这给出了错误消息

Fetching package metadata:
Error: No packages found in current win-64 channels matching: anaconda

You can search for this package on Binstar with

    binstar search -t conda anaconda

What am I doing wrong? How do I tell conda to create an environment based on the packages in this directory?

我究竟做错了什么?如何告诉 conda 基于此目录中的包创建环境?

回答by asmeurer

The pkgs directory is not a channel. The flag you are looking for is --unknown, which causes conda to include files in the pkgsdirectory even if they aren't found in one of the channels.

pkgs 目录不是频道。您要查找的标志是--unknown,这会导致 conda 将文件包含在pkgs目录中,即使在其中一个频道中找不到这些文件。

回答by hsparra

Have you tried without the --offline?

你试过没有 --offline 吗?

conda create -n anaconda python=3.4 --channel PATHTO\Anaconda_py3

This works for me if I am not connected to the Internet if I do have anaconda already on the machine but in another location. If you are connected to the Internet when you run this command you will probably get an error associated with not finding something on Binstar.

如果我没有连接到互联网,如果我的机器上已经有 anaconda 但在另一个位置,这对我有用。如果您在运行此命令时连接到 Internet,您可能会收到与在 Binstar 上找不到内容相关的错误。

回答by Arthur Alvim

You could try cloning root which is the base env.

您可以尝试克隆作为基础环境的 root。

conda create -n yourenvname --clone root

conda create -n yourenvname --clone root

回答by Urhixidur

I found the simplest method to be as follows:

我发现最简单的方法如下:

  1. Run 'conda create --name namepackage' with no special switches
  2. Copy the URL of the first package it tried (unsuccessfully) to download
  3. Use the URL on a connected machine to fetch the tar.bz2
  4. Copy the tar.bz2 to the offline machine's /home/user/anaconda3/pkgs
  5. Deploy the tar.bz2 in place
  6. Delete the now unneeded tar.bz2
  7. Repeat until the 'conda create' command succeeds
  1. 运行“conda create --name name package”,没有特殊开关
  2. 复制它尝试(不成功)下载的第一个包的 URL
  3. 使用连接机器上的 URL 来获取 tar.bz2
  4. 将tar.bz2复制到离线机器的/home/用户/anaconda3/pkgs
  5. 就地部署 tar.bz2
  6. 删除现在不需要的 tar.bz2
  7. 重复直到“conda create”命令成功

回答by hgcrpd

In addition to copying the pkgsfolder, you need to index it, so that condaknows how to find the dependencies. See this ticketfor more details and this scriptfor an example of indexing the pkgsfolder.

除了复制pkgs文件夹之外,您还需要对其进行索引,以便conda知道如何查找依赖项。有关更多详细信息,请参阅此票证,有关索引文件夹的示例,请参阅脚本pkgs

Using --unknownas @asmeurer suggests will only work if the package you're trying to install has no dependencies, otherwise you will get a "Could not find some dependencies" error.

--unknown仅当您尝试安装的软件包没有依赖项时,才按照@asmeurer 的建议使用,否则您将收到“找不到某些依赖项”错误。

Cloning is another option, but this will give you all root packages, which may not be what you want.

克隆是另一种选择,但这会给你所有的根包,这可能不是你想要的。

回答by nocturno

Here's what worked for me in Linux -

这是在 Linux 中对我有用的东西 -

(a) Create a blank environment - Just create an empty directory under $CONDA_HOME/envs. Verify with - conda info --envs.

(a) 创建一个空白环境 - 只需在 $CONDA_HOME/envs 下创建一个空目录。使用 - conda info --envs 进行验证。

(b) Activate the new env - source activate

(b) 激活新的 env - source activate

(c) Download the appropriate package (*.bz2) from https://anaconda.org/anaconda/repoon a machine with internet connection and move it to the isolated host.

(c)在具有 Internet 连接的机器上从https://anaconda.org/anaconda/repo下载适当的包 (*.bz2)并将其移动到隔离主机。

(d) Install using local package - conda install . For example - conda install python-3.6.4-hc3d631a_1.tar.bz2, where python-3.6.4-hc3d631a_1.tar.bz2 exists in the current dir.

(d) 使用本地包安装 - conda install 。例如 - conda install python-3.6.4-hc3d631a_1.tar.bz2,其中 python-3.6.4-hc3d631a_1.tar.bz2 存在于当前目录中。

That's it. You can verify by the usual means (python -V, conda list -n ). All related packages can be installed in the same manner.

就是这样。您可以通过通常的方式(python -V, conda list -n )进行验证。所有相关的软件包都可以以相同的方式安装。

回答by Bill

I'm not sure whether this contradicts the other answers or is the same but I followed the instructions in the conda documentationand set up a channel on the local file system.

我不确定这是否与其他答案相矛盾或相同,但我按照conda 文档中的说明在本地文件系统上设置了一个通道。

Then it's a simple matter of moving new package files to the local directory, running conda indexon the channel sub-folder (which should have a name like linux-64).

然后将新的包文件移动到本地目录,conda index在通道子文件夹(应该有一个类似的名称linux-64)上运行是一件简单的事情。

I also set the Anaconda config setting offlineto Trueas described herebut not sure if that was essential.

我还将 Anaconda 配置设置设置offlineTrue如此处所述但不确定这是否必要。

Hope that helps.

希望有帮助。

回答by Simba

Short answer: copy the whole environment from another machinewith the same OS.

简短回答:具有相同操作系统的另一台机器复制整个环境

Why

为什么

Dependency. A package depends on other packages. When you install a package online, the package manager condaanalyzes the package dependencies and install all the required packages for you.

依赖性。一个包依赖于其他包。当你在线安装一个包时,包管理器会conda分析包的依赖关系并为你安装所有需要的包。

The dependency is especially heavy in anaconda. Cause anacondais a meta package depends on another 160+ packages.

anaconda. 原因anaconda是一个元包依赖于另一个 160 多个包。

Meta packages,are packages do not contain actual softwares and simply depend on other packages to be installed.

元包,是不包含实际软件的包,仅依赖于要安装的其他包。

It's totally absurd to download all these dependencies one by one and install them on the offline machine.

把这些依赖一一下载,安装在离线机器上,简直是荒唐。

Detail Solution

详细解决方案

  1. Get condainstalled on another machine with same OS. Install the packages you need in an isolated virtual environment.

    # create a env named "myvenv", name it whatever you want
    # and install the package into this env
    conda create -n myvenv --copy anaconda
    

    --copyis used to

    Install all packages using copies instead of hard- or soft-linking.

  2. Find where the environments are stored with

    conda info
    

    The 1st value of key "envs directories" is the location. Go there and package the whole sub-folder named "myvenv" (the env name in previous step) into an archive.

  3. Copy the archive to your offline machine. Check "envs directories" from conda info. And extract the environment from the archive into the env directory on the offline machine.

  4. Done.

  1. 获得conda安装了相同的OS另一台机器上。在隔离的虚拟环境中安装您需要的软件包。

    # create a env named "myvenv", name it whatever you want
    # and install the package into this env
    conda create -n myvenv --copy anaconda
    

    --copy习惯于

    使用副本而不是硬链接或软链接安装所有软件包。

  2. 查找环境的存储位置

    conda info
    

    键“envs目录”的第一个值是位置。去那里并将名为“myvenv”(上一步中的 env 名称)的整个子文件夹打包到一个存档中。

  3. 将存档复制到您的离线机器。从conda info. 并将环境从存档中解压到离线机器上的 env 目录中。

  4. 完毕。

回答by patrick

A lot of the answers here are not 100% related to the "when offline" part. They talk about the rest of OP's question, not reflected in question title.

这里的很多答案都不是 100% 与“离线时”部分相关的。他们谈论 OP 的其余问题,而不是反映在问题标题中。

If you came here because you need offline env creation on top of an existing Anaconda install you can try:

如果您来到这里是因为您需要在现有 Anaconda 安装之上创建离线 env,您可以尝试:

conda create --offline --name $NAME

You can find the --offlineflag documented here

您可以在此处找到记录的--offline标志