pipenv

本文的示例代码参考flask-basic

目录

What

官方版

1
2
3
4
5
Pipenv: Python Development Workflow for Humans

Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. Windows is a first--class citizen, in our world.

It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever--important Pipfile.lock, which is used to produce deterministic builds.

精华版

1
pipenv = pip + virtualenv + Pipfile&Pipfile.lock

对照版

Node Python
包管理器 npm pip
环境隔离 全局(-g) 本地(默认) virtualenv
依赖描述 package.json Pipfile
版本锁定 (官方)无 Pipfile.lock

关于pipenv更多介绍 可以参考 pipenv

How

Installation

1
2
3
4
5
6
7
python --version
# Python 3.5.2

pip install pipenv

pipenv --version
# pipenv, version 2018.10.13

Setup

1
mkdir flask-basic && cd flask-basic
1
2
3
pipenv --python 3.7

cat Pipfile
1
2
3
4
5
6
7
8
9
10
11
[[source]]
name = "pypi"
verify_ssl = true
url = "https://pypi.org/simple"

[packages]

[requires]
python_version = "3.7"

[dev-packages]
1
2
3
4
pipenv shell

python --version
# Python 3.7.0

关于pipenv更多参数 可以参考”pipenv -h”

1
2
3
pipenv install flask

pipenv graph
1
2
3
4
5
6
Flask==1.0.2
- click [required: >=5.1, installed: 7.0]
- itsdangerous [required: >=0.24, installed: 1.1.0]
- Jinja2 [required: >=2.10, installed: 2.10]
- MarkupSafe [required: >=0.23, installed: 1.1.0]
- Werkzeug [required: >=0.14, installed: 0.14.1]

Project

1
vim app.py
1
2
3
4
5
6
7
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
return '<h1>Hello Flask!</h1>'
1
2
3
4
pipenv run flask run

curl localhost:5000
# <h1>Hello Flask!</h1>

参考