码迷,mamicode.com
首页 > 编程语言 > 详细

Python 3 使用venv创建虚拟环境

时间:2017-09-23 16:12:20      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:virtual   作用   xxxx   rtu   use   演示   相互   xxx   产生   

Python 3.3以上使用venv来代替了原来Python2使用的virtualenv创建虚拟环境。

虚拟环境的作用是使得不同项目的Python包之间不会相互干扰,避免了由此产生的各种问题。

现在演示下如何在桌面创建一个虚拟环境

C:\Users\dell\Desktop>mkdir python3VenvTest
C:\Users\dell\Desktop>cd python3VenvTest
C:\Users\dell\Desktop\python3VenvTest>python -m venv test

这样便创建好了一个名为test的虚拟环境,由于虚拟环境中的包是拷贝自电脑本身的Python,所以不建议在本机Python上安装过多第三方模块。

test的目录下有三个文件夹Include,Lib,Scripts,一个文件pyvenv.cfg。

启动该虚拟环境的方法是:

C:\Users\dell\Desktop\python3VenvTest>test\Scripts\activate.bat
(test) C:\Users\dell\Desktop\python3VenvTest>

接着,和一般安装Python包的步骤一样,使用pip install xxxx来安装你所需要的包。

退出虚拟环境的方法是:

(test) C:\Users\dell\Desktop\python3VenvTest>test\Scripts\deactivate.bat
C:\Users\dell\Desktop\python3VenvTest>

这样便退出了虚拟环境,下次想要进入虚拟环境在对应的路径输入命令activate.bat就能进入。

Python 3 使用venv创建虚拟环境

标签:virtual   作用   xxxx   rtu   use   演示   相互   xxx   产生   

原文地址:http://www.cnblogs.com/FZfangzheng/p/7581387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!