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.
Pipenv is primarily meant to provide users and developers of applications with an easy method to setup a working environment. For the distinction between libraries and applications and the usage of setup.py vs Pipfile to define dependencies, see ☤ Pipfile vs setup.py.
总结成一句话: pipenv类似于node的npm, rust的cargo, 把原来开发流程中virtualenv和pip组合用法整合到一个工具中来了。
brew install pipenv
pip install pipenv
如果是老项目本身已经存在虚拟环境, pipenv会自动检测到。
pipenv --two 使用Python2创建virtualenv
pipenv --three 使用Python3创建virtualenv
pipenv --python 3.6.5 使用指定的Python版本创建virtualenv
创建成功后, 会自动进入virtualenv。
exit
pipenv shell
pipenv --venv
pipenv install request django ...
如果项目本身有requirements.txt
, 可以指定从requirements.txt
安装包:
pipenv install -r path/to/requirements.txt
可以在安装virtualenv同时安装相关依赖包:
pipenv install -r path/to/requirements.txt --python 3.6.5
安装完成后在项目当前目录会生成 Pipfile
和 Pipfile.lock
两个文件。
默认pipenv是从官方pypi源去安装依赖包, 国内用户访问会比较慢, 我们可以编辑 Pipfile
中相关内容,使用国内的阿里云pypi镜像源。
[[source]]
url = "http://mirrors.aliyun.com/pypi/simple"
verify_ssl = false
name = "pypi"
Pipfile中的包分成了production
和dev
两种环境的包, 本地开发可以直接安装dev
环境相关的包:
pipenv install -d[--dev]
生产环境 安装包建议使用Pipfile.lock
来安装:
pipenv install --ignore-pipfile
可以使用--system
参数告诉pipenv将Pipfile
中的包安装到父系统中, 而不是安装到virtualenv里,特别是在容器部署的时候:
pipenv install --system --deploy
更多用法参考: Pipenv