pipenv入门指南

前言

pipenv是书写flask的大神kennethreitz的新作;pipenv集成了virtualenv和pip等工具,让你从requirements.pip以及virtualenv的环境中解放出来。并且他还集成了pyenv的选择python版本,可以说是所向披靡了。

这是他的原话:

You no longer need to use pip and virtualenv separately. They work together.
Managing a requirements.txt file can be problematic, so Pipenv uses the upcoming Pipfile and Pipfile.lock instead, which is superior for basic use cases.
Hashes are used everywhere, always. Security. Automatically expose security vulnerabilities.
Give you insight into your dependency graph (e.g. $ pipenv graph).
Streamline development workflow by loading .env files.

相信随着pipenv更加流行,许多工具也会在自己的环境中对pipenv提供支持,解决许多令人不舒服的问题,也能更好的提高编辑的舒适度。

安装pipenv

$ pip install pipenv

创建虚拟环境 virtualenv

  1. 当不存在一个虚拟环境的时候,pipenv将会自动创建一个环境
  2. 你也可以手动创建虚拟环境:
    1. $ pipenv --three 创建Python3虚拟环境
    2. $ pipenv --two 创建Python2虚拟环境
  3. 其他的东西和virtualenv是一样的。

安装包

比如你要使用requests(是的也是这个大神写的)。

$ pipenv install requests

安装完成后,会生成Pipfile以及Pipfile.lock;这一点很像npm.

其他命令

  1. 激活当前虚拟环境 pipenv shell
  2. 运行虚拟环境中的命令 pipenv run python
  3. 把你的依赖图输出出来 pipenv graph
  4. 安装当前目录的相关依赖 pipenv install

使用问题

目前我使用的时候也会多少存在问题,比如说我看不见下载的进度条,默认不是开启的;

然后就是因为网络环境的问题,我的pip.conf设置不能应用到pipenv上,我需要自己手动更改Pipfile,这一点有些麻烦。

后记

本身我想把这个文章针对的群体稍微降降,针对一些技术能力不是特别高的群体,但是存在一些问题,比如有些东西是需要一定知识才能看懂的。如果出现了不懂的内容,尽量自己查找一下吧。