Conda Pack

摘要:

移植python环境一般用于以下两种情况:

  1. 别人要运行你的代码,但是没有你的python环境,如果要一个一个python包进行安装,则非常麻烦,并且有时候还安装出现问题。
  2. 有一个包始终安装不上,但是在你的另一个python环境下有,或者在别人的环境中存在,这个时候就可以将python环境打包,移植到你的电脑上,然后激活该环境,运行对应的项目。

〓 Table of Contents 〓




conda pack 流程讲解

〓 ReTURN 〓

安装Conda-Pack

在打包之前如果没有conda-pack包的话,需要安装pip install conda-pack

进行python环境打包

1
2
3
4
5
6
7
8
9
conda info -e
# conda environments:
#
base * /miniconda38
IMavatar /miniconda38/envs/IMavatar
IMavatar_v2 /miniconda38/envs/IMavatar_v2
deca-env /miniconda38/envs/deca-env
flare /miniconda38/envs/flare
flare2 /miniconda38/envs/flare2
1
conda pack -n $环境名字 -o $压缩包名字.tar.gz
1
2
3
4
# 运行时样例
Collecting packages...
Packing environment at '/miniconda38/envs/deca-env' to 'deca-env--imavatar-data-prepro-env.tar.gz'
[################################## ] | 87% Completed | 2min 19.6s

接下来,传输这个压缩文件  $压缩包.tar.gz 到你所需要的服务器,并放到anaconda目录的envs文件夹路径下。

1
2
3
4
5
# 解压这个conda pack的环境
tar -zxvf $压缩包.tar.gz -C $环境名字
# 实例
mkdir /miniconda38/envs/nha
tar -zxvf nha.tar.gz -C /miniconda38/envs/nha

 注意 

conda pack方法无法跨操作系统进行环境迁移。只能linux到linux,windows到windows,mac到mac。

报错调试

包不一致

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ollecting packages...
CondaPackError:
Files managed by conda were found to have been deleted/overwritten in the
following packages:

- pyyaml 6.0:
lib/python3.7/site-packages/PyYAML-6.0-py3.7-linux-x86_64.egg-info/PKG-INFO
lib/python3.7/site-packages/PyYAML-6.0-py3.7-linux-x86_64.egg-info/SOURCES.txt
lib/python3.7/site-packages/PyYAML-6.0-py3.7-linux-x86_64.egg-info/dependency_links.txt
+ 5 others
- dataclasses 0.8:
lib/python3.7/site-packages/dataclasses-0.8.dist-info/INSTALLER
lib/python3.7/site-packages/dataclasses-0.8.dist-info/LICENSE.txt
lib/python3.7/site-packages/dataclasses-0.8.dist-info/METADATA
+ 5 others
- pytorch 1.7.0:
lib/python3.7/site-packages/torch-1.7.0-py3.7.egg-info/PKG-INFO
lib/python3.7/site-packages/torch-1.7.0-py3.7.egg-info/SOURCES.txt
lib/python3.7/site-packages/torch-1.7.0-py3.7.egg-info/dependency_links.txt
+ 3 others

This is usually due to `pip` uninstalling or clobbering conda managed files,
resulting in an inconsistent environment. Please check your environment for
conda/pip conflicts using `conda list`, and fix the environment by ensuring
only one version of each package is installed (conda preferred).

首先,进入你想要打包的那个环境,运行以下命令:

1
conda list

之后再进行pack,这个报错自己就消失了

无法pack源码编译的包

报错信息

1
2
3
4
5
6
Collecting packages...
CondaPackError: Cannot pack an environment with editable packages
installed (e.g. from `python setup.py develop` or
`pip install -e`). Editable packages found:

- /data/lijiawei421/eskandar/projects/3Drecon/point_avatar_deps/pytorch3d

pack方式变动

1
conda pack -n point-avatar -o pointavatar.tar.gz --ignore-editable-packages

解压缩使用

1
2
3
4
mkdir ~/ananconda/envs/point-avatar
tar -xf pointavatar.tar.gz -C ~/ananconda/envs/point-avatar
cd ~/ananconda/envs/point-avatar
source ./bin/activate
作者

Jiawei Li

发布于

2024-06-03

更新于

2024-06-03

许可协议