欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

理解pipenv in Python

程序员文章站 2022-05-07 15:13:14
...
  • Prerequisite

    理解Pipfile vs. setup.py || applications vs. libraries

  • Pipenv (Homepage)

    requests作者 K e n R e i t z Ken Reitz KenReitz发布于2017.1.22.

    Windows is a first-class citizen, in our world.

    Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yern, etc.) to the Python world.

    It harnesses Pipfile, pip, and virtualenv into one single toolchain.

    It automatically creates and manages a virtualenv for you 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.

    Pipenv 集成包管理+虚拟环境,通过Pipfile,Pipfile.lock以实现.针对虚拟环境,不再需要activate and deactivate

  • Installing Pipenv

    pipx

    pipenv

    pip install --user pipx 
    pipx ensurepath
    pipx install pipenv 
    
  • 基础用法

    详情参见:

    Announcing Pipenv!

    Basic Usage if Pipenv

    Pipenv & Virtual Environments

    Pipenv CLI Reference

    Pipenv manages dependencies on a per-project basis. To install packages, change into your projects’s directory (or just an empty directory for this tutorial) and run:

    cd project_folder
    pipenv install requests
    pipenv shell # activate environment
    touch script.py
    pipenv run python script.py
    pipenv uninstall <package>
    pipenv --rm # remove the virtualenv
    

    Pipenv will install requests library and create a Pipfile for you in your project’s directory. The Pipfile is used to track which dependencies your project needs in case you need to re-install them, such as when you share your projects with others.

    If it already has a requirements.txt file, it will generate a Pipfile file with the requirements and a virtual environment folder, otherwise, it will generate an empty Pipfile file.

    If you disliked or changed your mind about somthing that you have installed:

    pipenv uninstall <package>

    To activate the virtual environment that pipenv generated:

    pipenv shell

    to leave the environment:

    exit

    Using pipenv run ensures that your installed packages are available to your scripts. It’s also possible to spawn a new shell that ensures all commands have access to your installed packages with pipenv shell.

  • References

  1. How are Pipfile and Pipfile.lock used?