Back to Python#Installation

See also pipvirtualenv

pipenv

pipenv 是 Pipfile 主要倡导者、requests 作者 Kenneth Reitz 写的一个命令行工具,主要包含了 Pipfile、pip、click、requests 和 virtualenv。Pipfile 和 pipenv 本来都是Kenneth Reitz的个人项目,后来贡献给了 pypa 组织。Pipfile 是社区拟定的依赖管理文件,用于替代过于简陋的 requirements.txt 文件。

1. Installation

# MacOS
$ brew install pipenv
# Debian
$ sudo apt install pipenv
# with pip
$ pip install pipenv
# crude install
$ curl https://raw.githubusercontent.com/kennethreitz/pipenv/master/get-pipenv.py | python

1.1. Usage Examples

Create a new project using Python 3.7, specifically:
   $ pipenv --python 3.7

   Remove project virtualenv (inferred from current directory):
   $ pipenv --rm

   Install all dependencies for a project (including dev):
   $ pipenv install --dev

   Show a graph of your installed dependencies:
   $ pipenv graph

   Check your installed dependencies for security vulnerabilities:
   $ pipenv check

   Install a local setup.py into your virtual environment/Pipfile:
   $ pipenv install -e .

   Locate the project:
   $ pipenv --where

   Locate the virtualenv:
   $ pipenv --venv

1.2. Other Commands

2. Pipfile

Pipfile 文件是 requirements.txt 的替代,采用 TOML 格式。

一个项目对应一个 Pipfile,支持开发环境与正式环境区分。默认提供 default 和 development 区分。 提供版本锁支持,存为 Pipfile.lock。

https://github.com/pypa/pipfile

https://pipfile.pypa.io/ document

2.1. sample

[[source]]
url = 'https://pypi.python.org/simple'
verify_ssl = true
name = 'pypi'

[requires]
python_version = '2.7'

[packages]
requests = { extras = ['socks'] }
records = '>0.5.0'
django = { git = 'https://github.com/django/django.git', ref = '1.11.4', editable = true }
"e682b37" = {file = "https://github.com/divio/django-cms/archive/release/3.4.x.zip"}
"e1839a8" = {path = ".", editable = true}
pywinusb = { version = "*", os_name = "=='nt'", index="pypi"}

[dev-packages]
nose = '*'
unittest2 = {version = ">=1.0,<3.0", markers="python_version < '2.7.9' or (python_version >= '3.0' and python_version < '3.4')"}

3. click

click 是 Flask 作者 Armin Ronacher 写的命令行库。

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo('Hello %s!' % name)

if __name__ == '__main__':
    hello()

https://click.palletsprojects.com/

4. Reference

MainWiki: pipenv (last edited 2019-10-01 03:02:36 by twotwo)