Conda 环境离线迁移(一)

一、直接方式(推荐)

将conda envs文件下,对应环境文件复制到离线环境下的envs文件

 

二、安装多个包

1.有网的服务器

1). 生成requirement.txt文件

# 在项目根目录下, 会把当前环境下面的pip安装包名,都放到文件中
# 方法一
pip freeze >/tmp/wheel_pip/requirements.txt
# 方法二
pipreqs . --encoding=utf8 --force
# 方法三 conda虚拟环境导出
conda list --export > requirements.txt

2).打包pip和wheel的whl文件

pip wheel --wheel-dir=/tmp/wheel_pip pip 
pip wheel --wheel-dir=/tmp/wheel_pip wheel

 

3). 打包所有依赖包的whl文件

pip wheel --wheel-dir=/tmp/wheel_pip -r requirements.txt 

4). 添加到压缩包

tar cf /tmp/wheel_pip  wheel_pip.tar

 

2.离线的服务器

1). 解压压缩包

wheel_pip.tar复制到离线的服务器,解压

cd /tmp/ & tar xf wheel_pip.tar ./

2). 安装pip

python get-pip.py --no-index --find-links=/tmp/wheel_pip

3). 安装wheel

pip install --no-index --find-links=/tmp/wheel_pip wheel

4). 安装其他包

pip install --no-index --find-links=/tmp/wheel_pip -r requirements.txt 
pip install --no-index --find-links=/data1/upload/wheel_pip -r /data1/upload/wheel_pip/requirements.txt 

三、安装单个包

1.有网的服务器打包

pip wheel --wheel-dir=/data1/anchor/lujianxing/  celery 
#指定包的版本
pip wheel --wheel-dir=/data1/anchor/lujianxing/  celery==3.1.18 

wheel包的地址

ll /data1/anchor/lujianxing/celery-3.1.18-py2.py3-none-any.whl 

2.同步文件到正式环境

3. 无网的服务器安装

cd /data1/upload/
pip install celery-3.1.18-py2.py3-none-any.whl

 

参考内容

  1. 使用Pip在离线环境安装Python依赖库
  2. Pip wheel 的下载第三方包
  3. python生成requirements.txt的两种方法
  4. Anaconda Python版本下载链接
  5. 深度学习Python环境打包到另外一台电脑(详细教程)
  6. Python | Conda pack 进行环境打包
  7. conda 离线子环境 升级python版本
posted @ 2023-08-02 10:57  piggy侠  阅读(1593)  评论(0)    收藏  举报