Pipenv

Pipenv是pip和virtualenv的結合體,它能夠更方便地建立和管理python虛擬環境。python

Pipenv的基本用法以下:shell

1. 輸出虛擬環境信息(能夠驗證當前目錄的虛擬環境是否已經建立)

pipenv --venv
複製代碼

2. 建立虛擬環境

pipenv --python 3.7
pipenv --three
複製代碼

虛擬環境建立完成之後,會在當前目錄下生成2個文件PipfilePipfile.lockflask

3. 移除虛擬環境

pipenv --rm
複製代碼

4. 安裝依賴包

# 如安裝flask包
pipenv install flask
# 在開發環境安裝pytest
pipenv install pytest --dev
複製代碼

安裝依賴包後,Pipfile中packages(或de v-packages)模塊下會記錄已安裝的依賴包信息,Pipfile.lock中記錄了依賴包的精確版本信息,它能夠用來避免版本不一致引發的兼容性問題,建議不要手動更改Pipfile.lock文件內容。安全

5. 顯示已安裝的依賴包

pipenv graph
複製代碼

6. 檢查安裝的依賴包是否存在安全漏洞

pipenv check
複製代碼

7. 卸載依賴包

# 卸載指定包
pipenv uninstall flask
# 卸載全部依賴包
pipenv uninstall --all
複製代碼

8. 進入虛擬環境

pipenv shell
複製代碼

進入虛擬環境之後,執行python命令調用的就是虛擬環境中的python解釋器,與系統安裝的python環境就沒有關係了。另外,進入虛擬環境後使用exit退出當前虛擬環境。bash

9. 查看python解釋器路徑

pipenv --py
複製代碼

10. 幫助

pipenv --help
複製代碼

經過pipenv的幫助手冊能夠查看更詳細的用法。ide

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.
複製代碼
相關文章
相關標籤/搜索