写给前端的Python依赖管理指北

栏目: Python · 发布时间: 6年前

内容简介:在Python的项目中,我们可以通过pip来安装依赖包,但是不像npm install,pip默认安装的依赖包会挂在全局上,不利于项目工程协作。这时候需要一款类似npm的工具记录我们的项目依赖Pipenv。

概述

Python 的项目中,我们可以通过pip来安装依赖包,但是不像npm install,pip默认安装的依赖包会挂在全局上,不利于项目工程协作。

写给前端的Python依赖管理指北

这时候需要一款类似npm的 工具 记录我们的项目依赖Pipenv。

安装Pipenv

我们通过pip安装Pipenv:

$ pip install pipenv

安装之后,我们开始使用它来创建本地项目,为方便大家理解,将npm与Pipenv的使用方式进行对比。

写给前端的Python依赖管理指北

创建本地项目

  • Nodejs
$ npm init --yes

不同于Nodejs的npm,Python的Pipenv初始化项目需要经过两步:

  1. 创建虚拟环境
  2. 激活虚拟环境
  • Python
$ pipenv install
$ pipenv shell

这时候Python会针对这个项目创建一个虚拟环境。项目下会出现一个文件 Pipfile,对应npm的 package.json 用于记录项目依赖信息。

写给前端的Python依赖管理指北

安装依赖包

当我们把自己的项目提交到git上,别人拉下工程后,就需要安装该工程的所有依赖:

  • Nodejs
$ npm install
  • Python
$ pipenv install

当我们需要往项目添加新的依赖包,并记录到工程里:

  • Nodejs
$ npm install xxx --save
  • Python
$ pipenv install xxx

安装到开发环境:

  • Nodejs
$ npm install xxx --save-dev
  • Python
$ pipenv install xxx --dev

最后

通过pipenv我们可以像npm管理Nodejs工程一样管理python工程,更多细节可以参考pipenv官网: https://pipenv.readthedocs.io/en/latest/


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms Sequential & Parallel

Algorithms Sequential & Parallel

Russ Miller、Laurence Boxer / Charles River Media / 2005-08-03 / USD 59.95

With multi-core processors replacing traditional processors and the movement to multiprocessor workstations and servers, parallel computing has moved from a specialty area to the core of computer scie......一起来看看 《Algorithms Sequential & Parallel》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具