Python:初识virtualenv

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chaiyu2002/article/details/83827879

前言

从9月中旬,开始用Python开发项目,开始接触virtualenv,今天抽空,对此做一个总结。

正文

virtualenv is a tool to create isolated Python environments.

从virtualenv的官网来看,virtualenv主要用来创建一个虚环境,用来创建一个隔离的Python的环境。例如在DRF的官网指导中:

virtualenv env
source env/bin/activate

这里可以参考廖雪峰的文章,他讲的很清楚。

这种用法是一种标准用法,也是一种传统的用法,现在更为流行的用法是使用virtualenvwrapper。

virtualenvwrapper is a set of extensions to Ian Bicking’s virtualenv tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.

从上文来看,单独使用virtualenv开发多个项目有可能会在依赖上引入冲突,使用virtualenvwrapper就是为了帮助解决这个问题。

使用方法:

Quick-Start
Run: workon
A list of environments, empty, is printed.
Run: mkvirtualenv temp
A new environment, temp is created and activated.
Run: workon
This time, the temp environment is included.

运行mkvirtualenv temp会创建一个temp的环境,然后运行workon,这个时候这个虚环境便被引入进来,运行workon temp进入这个虚环境,然后可以开始你的工作了。

参考

https://virtualenv.pypa.io/en/latest/
https://www.django-rest-framework.org/tutorial/1-serialization/
https://virtualenvwrapper.readthedocs.io/en/latest/
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432712108300322c61f256c74803b43bfd65c6f8d0d0000

猜你喜欢

转载自blog.csdn.net/chaiyu2002/article/details/83827879
今日推荐