使用pipenv代替virtualenv管理python包

数字踏浪客
• 阅读 3222

前言

第一次接触到 pipenv 是因为看到@董明伟大神的《使用pipenv管理你的项目》,之前可能和大家的选择类似使用 virtualenv 或者 pyenv 来管理 python 的包环境。virtualenv 是针对python的包的多版本管理,通过将python包安装到一个模块来作为python的包虚拟环境,通过切换目录来实现不同包环境间的切换。pyenv 是针对 python 版本的管理,通过修改环境变量的方式实现;虽然我自己对pipenv的掌握程度还不深,但是我自己能感受到更加简单而清晰的python包管理方式,并且pipenv还是Python官方正式推荐的python包管理工具。原文如下:

Pipenv — the officially recommended Python packaging tool from Python.org, free (as in freedom).

Pipenv 官方推荐的 Python 包管理工具

更新历史

2017年04月25日 - 初稿

阅读原文 - https://wsgzao.github.io/post...

扩展阅读

Pipenv - https://docs.pipenv.org/
Pipenv & 虚拟环境 - http://pythonguidecn.readthed...


推荐阅读

使用pipenv管理你的项目 @董伟明
http://www.dongwm.com/archive...

【 python 基础系列 】 - pipenv 试用过程分享
http://pylixm.cc/posts/2018-0...

Pipenv 官方简介

Pipenv: Python Development Workflow for Humans

Pipenv — the officially recommended Python packaging tool from Python.org, free (as in freedom).

Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. Windows is a first–class citizen, in our world.

It automatically creates and manages a virtualenv for your 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代替virtualenv管理python包

The problems that Pipenv seeks to solve are multi-faceted:

You no longer need to use pip and virtualenv separately. They work together.
Managing a requirements.txt file can be problematic, so Pipenv uses the upcoming Pipfile and Pipfile.lock instead, which is superior for basic use cases.
Hashes are used everywhere, always. Security. Automatically expose security vulnerabilities.
Give you insight into your dependency graph (e.g. $ pipenv graph).
Streamline development workflow by loading .env files.

Pipenv 安装和使用

我的使用深度不高,就以目前我实际使用pipenv的方式为例
# pip 离线下载
# pip install --download DIR -r requirements.txt
mkdir pipenv
pip install -d ~/pipenv/ pipenv

# pip 离线安装pipenv
pip install --no-index --find-links=pipenv/ pipenv

# 使用pipenv创建虚拟环境
mkdir win_ansible
cd win_ansible
pipenv shell
pip install --no-index --find-links=pip-ansible-2.4.3.0/ -r requirements.txt

# 升级ansible版本
pip install --no-index --find-links=pip-ansible-2.5.0/ -r requirements.txt -U

# 退出虚拟环境
exit

# 对不同开发用户自动创建python虚拟环境
vim ~/.bash_profile
pipenv shell

# 虚拟环境会在当前用户家目录自动创建
test101@JQ/root#su - wangao
Spawning environment shell (/bin/bash). Use 'exit' to leave.
test101@JQ/home/wangao$. /home/wangao/.local/share/virtualenvs/wangao-iOSX51hl/bin/activate

# 沿用pip创建requirements.txt,该方法相对Pipfile来说不是最佳
(wangao-iOSX51hl) test101@JQ/home/wangao/git/ansible$cat requirements.txt 
--index-url=http://172.31.96.201:8081/simple/
--trusted-host=172.31.96.201
ansible
ansible-cmdb
pywinrm

# 通过gitlab同步控制python包环境
git checkout develop
git pull origin develop
pip install -r requirements.txt -U

推荐参考的文章

Python 2.6 升级至 Python 2.7 的实践心得 - https://wsgzao.github.io/post...
使用pypiserver快速搭建内网离线pypi仓库实践 - https://wsgzao.github.io/post...
RHEL7/CentOS7在线和离线安装GitLab配置使用实践 - https://wsgzao.github.io/post...

点赞
收藏
评论区
推荐文章
CuterCorley CuterCorley
4年前
商业数据分析从入门到入职(8)Python模块、文件IO和面向对象
前言本文先介绍了Python中程序、模块和包的基本使用,并在此基础上介绍了Python标准库。然后详细介绍了Python中的文件IO操作,包括文本文件、二进制文件的读写和其他IO操作。最后介绍了面向对象,包括类的定义、继承的使用、鸭子类型和魔法方法。一、程序、模块和包1.自定义模块和包之前我们使用的.ipynb文件都不是纯Python文件,
Stella981 Stella981
3年前
Scapy 从入门到放弃
0x00前言最近闲的没事,抽空了解下地表最强的嗅探和收发包的工具:scapy。scapy是一个python模块,使用简单,并且能灵活地构造各种数据包,是进行网络安全审计的好帮手。0x01安装因为2020年python官方便不再支持python2,所以使用python3安装。!(https://oscimg.oschina.net/os
Stella981 Stella981
3年前
MongoDB学习【四】—pymongo操作mongodb数据库
一、pymongodb的安装Python要连接MongoDB需要MongoDB驱动,这里我们使用PyMongo驱动来连接。pip安装pip是一个通用的Python包管理工具,提供了对Python包的查找、下载、安装、卸载的功能。安装pymongopython3m
Stella981 Stella981
3年前
Django学习之路2
virtualenv简介:virtualenv是一个创建独立python环境的工具。其要解决的最基本问题就是库的依赖和版本,以及间接权限。比如一个ubuntu环境默认安装了python2.7.11的版本,想要使用python3.5,如果再安装3.5,就会比较乱,再如pip安装的软件包,有一个项目用的事Django1.8的
Stella981 Stella981
3年前
Linux 下的 Python 多版本管理(pyenv)
简介提到Python环境管理,更多人可能会首先想到virtualenv。但与用于创建独立包环境的virtualenv不同,pyenv的作用仅限于维护不同版本的Python。它的使用不依赖于Python,是一个简单、独立的纯shell脚本工具。pyenv也以pyenvvirtualenv(https://www.oschin
Wesley13 Wesley13
3年前
python3.6虚拟环境以及flask的安装(常见问题)
准备基于python进行web应用开发Python3.3以上的版本通过venv模块原生支持虚拟环境,可以代替Python之前的virtualenv。该venv模块提供了创建轻量级“虚拟环境”,提供与系统Python的隔离支持。每一个虚拟环境都有其自己的Python二进制(允许有不同的Python版本创作环境),并且可以拥有自己独立的一套Python包
Stella981 Stella981
3年前
Python—版本和环境的管理工具(Pipenv)
pipenv简介虚拟环境本质是一个文件,是为了适应不同的项目而存在。pipenv相当于virtualenv和pip的合体。整合了pipvirtualenvPipfile,能够自动处理好包的依赖问题和虚拟环境问题,是最推荐使用的虚拟环境管理。过去用virtualenv管理requirements.txt文件可能会有
Stella981 Stella981
3年前
Pipenv管理项目环境
virtualenv使用不方便提升效率,管理更便捷pipenv新建环境:: pip3installpipenv !(https://img2018.cnblogs.com/blog/1733919/201907/1733919201907221312226901451026112.png) 在项目下,用pi
Stella981 Stella981
3年前
PyCharm 下引入anaconda的模块
搞科学计算和人工智能的人都会需要很多python模块例如:Numpy,Panda....anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项因为包含了大量的科学包,Anaconda的下载文件比较大,如果只需要某些包,或者需要节省带宽或存储空间,也可以使用Miniconda这个较小的发行版(
小万哥 小万哥
1年前
Python 包管理器入门指南
什么是PIP?PIP是Python包管理器,用于管理Python包或模块。注意:如果您的Python版本是3.4或更高,PIP已经默认安装了。什么是包?一个包包含了一个模块所需的所有文件。模块是您可以包含在项目中的Python代码库。检查是否安装了PIP在
浅谈Tox之一
tox是通用的virtualenv管理和测试命令行工具,可用于:1.使用不同的Python版本和解释器检查您的软件包是否正确安装2.在每个环境中运行测试,配置您选择的测试工具3.充当持续集成服务器的前端,大大减少了样板文件并合并了CI和基于shell的测试。
数字踏浪客
数字踏浪客
Lv1
坐观垂钓者,徒有羡鱼情。
文章
3
粉丝
0
获赞
0