python虚拟环境迁移

目标:

python虚拟环境迁移: 

将机器1虚拟环境下的包信息打包,之后到机器2上进行安装; 

 

1.首先在机器1命令行下,激活虚拟环境
wangju@wangju-HP-348-G4:~$ workon rlcVenv
2.在项目目录下新建一个whls文件夹(用来存储我们依赖包)然后在命令行下切换到whls目录

 cd到项目的whs目录

(rlcVenv) wangju@wangju-HP-348-G4:~$ cd /home/wangju/reponselogiccheck/whs

 

执行 pip freeze --all > requirements.txt 命 令 将安装包版本信息导入到requireents.txt文件中(该文件位置在执行cmd命令当前目录下,也就是whls下);
(rlcVenv) wangju@wangju-HP-348-G4:~/reponselogiccheck/whs$ pip freeze --all > requirements.txt

 

注意--all参数,加上此参数会将setuptools、urllib3包进行打包;如果不加,这两个不会打包。

将项目上传到git

 

 

机器2:
1.新建虚拟环境
 1 [root@67 ~]# mkvirtualenv rlcVenv
 2 Using base prefix '/usr/local/python3'
 3 New python executable in /root/.virtualenvs/rlcVenv/bin/python3.6
 4 Also creating executable in /root/.virtualenvs/rlcVenv/bin/python
 5 Installing setuptools, pip, wheel...
 6 done.
 7 virtualenvwrapper.user_scripts creating /root/.virtualenvs/rlcVenv/bin/predeactivate
 8 virtualenvwrapper.user_scripts creating /root/.virtualenvs/rlcVenv/bin/postdeactivate
 9 virtualenvwrapper.user_scripts creating /root/.virtualenvs/rlcVenv/bin/preactivate
10 virtualenvwrapper.user_scripts creating /root/.virtualenvs/rlcVenv/bin/postactivate
11 virtualenvwrapper.user_scripts creating /root/.virtualenvs/rlcVenv/bin/get_env_details
12 (rlcVenv) [root@67 ~]#

 

2.新建虚拟环境成功,会默认激活所创建的虚拟环境。如果使用现在的虚拟环境,需要先激活
3.克隆项目到机器2
 
 

4.进入项目下whls目录

(rlcVenv) [root@67 whs]# pwd
/home/wangju/gitProject/reponselogiccheck/whs

 5.执行命令安装包:

pip install -r requirements.txt #安装依赖包

如图所示,就开始安装了:

 可以运行一下项目,验证结果:

如图,项目跑起来就没问题了

 

参考文档:

导出本地虚拟环境中的信赖:

https://www.cnblogs.com/yhleng/p/9921641.html

 

导出pycharm创建的虚拟环境信赖

https://www.cnblogs.com/zhaijihai/p/10396396.html

posted @ 2019-08-05 14:53  wangju003  阅读(1742)  评论(0编辑  收藏  举报