问题
在使用conda进行python虚拟环境从本地开发环境到服务器生产环境迁移的过程中,过程如下:
1、打包本地文件
打包本地开发环境的对应的虚拟环境:
# 打包对象:
/anaconda3/envs/[envs_names]
/anaconda3/pkgs
2、上传生产环境
将pkgs包上传到服务器上并解压覆盖对应目录(miniconda目录下),将环境包放到服务器上(位置自己定),然后解压
3、克隆
执行下面命令:
conda create -n [new_envs_name] --clone[path to envs_names] --offline
参数解释:
-n [new_envs_name]:和正常创建conda的一样,创建新的虚拟环境的名字
–clone [path to envs_names]:需要迁移的虚拟环境文件夹的地址
–offline:离线安装的指令
出现以下错误:
CondaError: RuntimeError(u'EnforceUnusedAdapter called with url https://repo.continuum.io/pkgs/free/linux-64/jpeg-8d-0.tar.bz2\nThis command is using a remote connection in offline mode.\n',) CondaError: RuntimeError(u'EnforceUnusedAdapter called with url https://repo.continuum.io/pkgs/free/linux-64/jpeg-8d-0.tar.bz2\nThis command is using a remote connection in offline mode.\n',) CondaError: RuntimeError(u'EnforceUnusedAdapter called with url https://repo.continuum.io/pkgs/free/linux-64/jpeg-8d-0.tar.bz2\nThis command is using a remote connection in offline mode.\n',) ……
思路
类型错误:搜索了解到可能是conda版本bug导致的
解决方法
方法一(没有验证,不过看起来挺有道理的,可以尝试一下):安装时将pkgs内的urls和urls.txt两个文件删除了(文件内部是安装包的地址);
方法二:直接将环境包解压到miniconda的envs目录下,不过首次用conda activate
激活虚拟环境时会报一个conda init
之类的错误,用source activate env_name
就没问题了。