如何将安装在一台机器上的Anaconda环境转移到另一台机器上?[都安装了Ubuntu]

jtw3ybtb  于 2023-01-25  发布在  其他
关注(0)|答案(6)|浏览(307)

我一直在我的GuestOS ubuntu 14.04上使用Anaconda(4.3.23),它安装在HostOS windows 8.1上的Vmware上。我在anaconda中设置了一个环境,并安装了许多库,其中一些安装起来非常繁忙(不是直接的pip安装)。很少有库有内部依赖关系,必须从它们的git源代码一起构建。

问题我打算使用基于云的虚拟机(Azure GPU示例)来使用GPU。但我不想再次进入繁忙的安装,因为我不想浪费金钱的时间,它将花费我再次安装所有的包和库

是否有任何方法可以将我现有的env(已经安装了所有内容)传输/复制到云VM?

wf82jlnq

wf82jlnq1#

this documentation page的最末尾开始:
保存包以备将来用途:

conda list --export > package-list.txt

从导出文件重新安装程序包:

conda create -n myenv --file package-list.txt
fhity93d

fhity93d2#

如果conda list --export像这样失败...

执行conda list --export > package-list.txt将创建一个如下所示的文件:

# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
_tflow_1100_select=0.0.1=gpu
absl-py=0.5.0=py_0
astor=0.7.1=py_0
...

但是通过执行conda create -n myenv --file package-list.txt创建一个新的环境会给我这个错误:

Solving environment: ...working... failed

PackagesNotFoundError: The following packages are not available from current channels:

  - markdown==2.6.11=py_0
  ...

...然后尝试使用conda env export

根据this discussion,在源计算机上执行以下命令:

source activate yourEnvironment
conda env export --no-builds > file.txt

在目标计算机上执行:

conda env create --file /path/to/file.txt

conda env export生成的文件看起来有点不同,但它也包含pip包

name: yourEnvironment
channels:
  - conda-forge
  - defaults
dependencies:
  - absl-py=0.5.0
  ...
  - pip:
    - astroid==2.0.4
    ...
rkkpypqq

rkkpypqq3#

## You can try below approach to move all the package from one machine to other :
## Note : Machine that packages are being moved should be same and python version also should be same


$ pip install conda-pack


# To package an environment:

## Pack environment my_env into my_env.tar.gz

$ conda pack -n my_env

## Pack environment my_env into out_name.tar.gz

$ conda pack -n my_env -o out_name.tar.gz

## Pack environment located at an explicit path into my_env.tar.gz

$ conda pack -p /explicit/path/to/my_env

# After following above approach, you will end up with a tar.gz file. Now to install package from this zip file follow below approach.

## To install the environment:

## Unpack environment into directory `my_env`

$ mkdir -p my_env
$ tar -xzf my_env.tar.gz -C my_env

## Use Python without activating or fixing the prefixes. Most Python
## libraries will work fine, but things that require prefix cleanups
## will fail.

$ ./my_env/bin/python

## Activate the environment. This adds `my_env/bin` to your path

$ source my_env/bin/activate

## Run Python from in the environment

(my_env) $ python

## Cleanup prefixes from in the active environment.
## Note that this command can also be run without activating the environment
## as long as some version of Python is already installed on the machine.

(my_env) $ conda-unpack
oxf4rvwz

oxf4rvwz4#

您可以将整个Anaconda安装复制到云示例中。

0lvr5msh

0lvr5msh5#

根据github线程在源机器上执行以下命令:https://github.com/conda/conda/issues/3847

source activate yourEnvironment
conda env export --no-builds > environment.yml
    • 在目标计算机上执行:**
conda env create -f environment.yml

conda env export生成的文件看起来有点不同,但它也包含pip包:
名称:您的环境通道:

  • 康达福格
  • 默认依赖项:
  • 绝对值-ρ y = 0.5.0
  • 脉冲:
  • 星形线== 2.0.4 ...
cyej8jka

cyej8jka6#

我从this中找到了答案
您可以使用以下命令导出Anaconda环境:

conda env export > environment.yml

要在另一台计算机上重新创建它,请使用:

conda env create -f environment.yml

您可以根据需要修改environment.yml,因为某些python库可能已经过时,或者由于未来版本中的版本冲突。

相关问题