pipenv
是 Python官方推荐 的包管理工具。能够说,它集成了virtualenv
, pip
和pyenv
三者的功能。其目的旨在集合了全部的包管理工具的长处,如: npm
, yarn
, composer
等的优势。python
它可以自动为项目建立和管理虚拟环境,从Pipfile
文件添加或删除安装的包,同时生成Pipfile.lock
来锁定安装包的版本和依赖信息,避免构建错误。git
pipenv
主要解决了以下问题:github
pip
和virtualenv
, 如今它们合并在一块儿了requirements.txt
, 使用Pipfile
和Pipfile.lock
来代替python2
和python3
)pyenv
的条件下,能够自动安装须要的Python版本pip install pipenv -i https://pypi.douban.com/simple
Usage: pipenv \[OPTIONS\] COMMAND \[ARGS\]... Options: --where Output project home information. --venv Output virtualenv information. --py Output Python interpreter information. --envs Output Environment Variable options. --rm Remove the virtualenv. --bare Minimal output. --completion Output completion (to be eval'd). --man Display manpage. --support Output diagnostic information for use in GitHub issues. --site-packages Enable site-packages for the virtualenv. \[env var: PIPENV\_SITE\_PACKAGES\] --python TEXT Specify which version of Python virtualenv should use. --three / --two Use Python 3/2 when creating virtualenv. --clear Clears caches (pipenv, pip, and pip-tools). \[env var: PIPENV\_CLEAR\] -v, --verbose Verbose mode. --pypi-mirror TEXT Specify a PyPI mirror. --version Show the version and exit. -h, --help Show this message and exit. 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 Create a lockfile containing pre-releases: $ pipenv lock --pre 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 . Use a lower-level pip command: $ pipenv run pip freeze Commands: check Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile. clean Uninstalls all packages not specified in Pipfile.lock. graph Displays currently-installed dependency graph information. install Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile. lock Generates Pipfile.lock. open View a given module in your editor. run Spawns a command installed into the virtualenv. shell Spawns a shell within the virtualenv. sync Installs all packages specified in Pipfile.lock. uninstall Un-installs a provided package and removes it from Pipfile. update Runs lock, then sync.
# 安装包 $ pipenv install # 安装指定包版本 eg: $ pipenv install django=2.1.7 # 安装 pipfile.lock 中固定版本 $ pipenv install --ingnore-pipfile # 激活(进入)当前项目的虚拟环境 $ pipenv shell # 查看当前虚拟环境的路径 $ pipenv --venv # 安装开发依赖包 $ pipenv install pytest --dev # 图形显示包依赖关系(可检查安装包对其余包版本的要求) $ pipenv graph # 生成lockfile(pipenv install 默认会生成 lockfile 文件) $ pipenv lock # 删除某个安装包 $ pipenv uninstall django # 删除全部的安装包 $ pipenv uninstall --all # 退出当前虚拟环境 $ exit or ctrl+d # 删除当前虚拟环境 $ pipenv --rm
当在执行pipenv install
命令的时候,若是有一个requirements.txt
文件,那么会自动从requirements.txt
文件导入安装包信息并建立一个Pipfile
文件。一样能够使用
$ pipenv install -r path/to/requirements.txt
来导入requirements.txt
文件shell
$ pipenv --python 3
$ pipenv --python 3.6
$ pipenv --python 2.7.14npm
咱们也能够从Pipfile
和Pipfile.lock
文件来生成requirements.txt
django
注意⚠️:pipenv
会自动扫描系统寻找合适的版本信息,若是找不到的话,同时又安装了pyenv
, 它会自动调用pyenv
下载对应的版本的python安全
# 生成requirements.txt文件 $ pipenv lock -r # 生成dev-packages的requirements.txt文件 # pipenv lock -r -d
pipenv
包含了safety
模块,能够让咱们坚持安装包是否存在安全隐患。composer
pipenv check
pipenv
默认集成了flake8
, 能够用来检测编码风格ide
pipenv check --style test.py