pipenv的使用

1)安装:pip install pipenv

2)查看用法:pipenv
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.

3)创建:在项目目录下 pipenv install +你需要的包

例如 pipenv install torch==0.3.1

会自动创建Pipfile、Pipfile.lock、文件

打开Pipfile文件我们看到

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

[dev-packages]

[packages]
torch = "==0.3.1"

[requires]
python_version = "3.6" 

4)卸载某包:pipenv uninstall [package name]

5)使用:pipenv shell

激活python虚拟环境之后,运行python模块都在该虚拟环境中

6)退出:推出该环境运行 deactivate命令

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VSCode 和 Pipenv 都是 Python 开发过程中常用的工具,但是它们的作用并不完全相同。 **VSCode**: 这是一款由 Microsoft 提供的免费开源代码编辑器。它支持多种编程语言,包括 Python,并提供了丰富的插件生态系统,使得开发者可以根据需要安装各种功能强大的插件。对于 Python 开发者来说,VSCode 的优点在于它提供了代码自动完成、语法高亮显示、错误提示等功能,并且可以方便地集成 Jupyter Notebook 等交互式环境。此外,VSCode 还支持任务自动化和构建系统的集成,例如通过安装 `Python` 插件来处理虚拟环境配置、运行脚本等操作。 **Pipenv**: 这是一个用于 Python 包管理及虚拟环境管理的命令行工具。它的目标是简化依赖管理和包版本控制,帮助开发者轻松创建、维护以及分享项目所需的软件包。Pipenv 使用 `requirements.txt` 文件来记录项目的依赖项,并允许用户在同一环境中激活并管理多个 Python 版本和项目依赖。相比于其他包管理工具如 `pip`, `virtualenv`, 或 `conda`,Pipenv 更加强调了在单一环境中管理所有项目依赖的优势,并且它可以无缝集成到现有的工作流程中。 ### VSCode + Pipenv 工作流: 在实际应用中,开发者通常会将这两种工具结合使用: 1. **配置虚拟环境**:使用 Pipenv 创建一个虚拟环境,并通过 `pipenv shell` 激活该环境。这保证了每个项目都有独立的依赖库版本,避免了全局环境与项目之间的冲突。 2. **安装依赖**:在激活的虚拟环境中,使用 `pipenv install` 来安装项目所需的所有依赖,包括主程序及其外部依赖。这个过程会被记录在 `Pipfile.lock` 文件中,确保每次部署都能得到一致的结果。 3. **构建与测试**:开发者可以在 VSCode 中编写、调试和执行代码,同时利用 Pipenv 对依赖进行管理和检查,确保代码的运行依赖于正确的版本。 4. **共享项目**:通过 `.pypirc` 文件配置 PyPI 登录凭据,然后使用 `pipenv publish` 将项目发布到 PyPI,以便其他人可以直接通过 `pip install -U` 安装。 通过这种方式,开发者能够在一个统一的工作流程中有效地管理代码的开发、测试和部署过程,提高生产力和协作效率。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值