pipenv 命令笔记

1. 安装: pip install pipenv

		mac: `brew install pipenv`

2. 使用:

  1. 创建虚拟环境,指定Python版本----Create a new project using Python 3.7, specifically:
    $ pipenv --python 3.7

    pipenv --python 3
    pipenv --python 3.6
    pipenv --python 2.7.14
    
  2. 删除项目虚拟环境----Remove project virtualenv (inferred from current directory):
    $ pipenv --rm

  3. 安装包----Install all dependencies for a project (including dev):
    pipenv install --dev requests==2.13.0
    pipenv install requests==2.13.0

  4. 创建预发布的lockfile----Create a lockfile containing pre-releases:
    $ pipenv lock --pre

  5. 查看依赖图 Show a graph of your installed dependencies:
    $ pipenv graph

  6. Check your installed dependencies for security vulnerabilities:
    $ pipenv check

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

  8. Use a lower-level pip command:
    $ pipenv run pip freeze

  9. 用下面的命令可以启动一个在虚拟环境中的shell:
    pipenv shell
    如果不想启动shell,而是直接在虚拟环境中执行命令,可以使用run:
    pipenv run python --version

  10. 退出虚拟环境: exit

  11. 卸载:
    相应的还有命令来卸载第三方包,该命令还有两个参数–all和–all-dev用于卸载所有包和所有开发包。
    pipenv uninstall requests

  12. 更新
    查看所有需要更新的包:pipenv update --outdated
    更新所有包:pipenv update
    更新指定的包:pipenv update <包名>

  13. 从requirements.txt导入
    如果项目中有requirements.txt文件,pipenv会在安装的时候自动导入。如果需要导入其他位置的requirements.txt,可以用下面的命令:
    pipenv install -r path/to/requirements.txt

  14. 导出requirements.txt
    用下面的命令就可以将Pipfile和Pipfile.lock文件里面的包导出为requirements.txt文件。
    pipenv lock -r >> requirements.txt
    如果只想导出开发用的包,可以添加–dev参数:
    pipenv lock -r --dev

  15. 自动安装Python
    pipenv只能搜索系统中已经安装的Python版本,对于未安装的版本,会提示错误。但是如果你同时安装了pyenv的话,pipenv会自动发现pyenv,然后直接询问你是否要安装。这样一来,原来的工作流程是:用pyenv安装某个Python->用virtualenv或venv创建虚拟环境->用pip从requirements.txt中安装包->将来可能还要更新包。现在完全可以用pipenv一两条命令解决,真的是非常方便。

  16. 自动加载.env文件
    .env文件可以设置一些环境变量,在程序开发的时候模拟环境变量。pipenv也可以自动加载.env文件。

    $ cat .env
    HELLO=WORLD⏎
    
    $ pipenv run python
    Loading .env environment variables…
    Python 2.7.13 (default, Jul 18 2017, 09:17:00)
    [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.environ['HELLO']
    'WORLD'
    
  17. 环境变量支持
    在Pipfile中也可以引用环境变量的值,格式为${MY_ENVAR}$MY_ENVAR,在Windows系统中还支持%MY_ENVAR%

    [[source]]
    url = "https://${PYPI_USERNAME}:${PYPI_PASSWORD}@my_private_repo.example.com/simple"
    verify_ssl = true
    name = "pypi"
    
    [dev-packages]
    
    [packages]
    requests = {version="*", index="home"}
    maya = {version="*", index="pypi"}
    records = "*"
    
    

官方文档:https://pipenv.readthedocs.io/en/latest/advanced/#configuration-with-environment-variables
https://docs.pipenv.org/en/latest/
https://pipenv.readthedocs.io/en/latest/basics/#example-pipfile-pipfile-lock
参考博文:https://blog.csdn.net/u011054333/article/details/82891847

你可能感兴趣的:(python)