资讯专栏INFORMATION COLUMN

使用pipenv代替virtualenv管理python包

whidy / 3084人阅读

摘要:前言第一次接触到是因为看到董明伟大神的使用管理你的项目,之前可能和大家的选择类似使用或者来管理的包环境。是针对的包的多版本管理,通过将包安装到一个模块来作为的包虚拟环境,通过切换目录来实现不同包环境间的切换。

前言

第一次接触到 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.

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...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/41652.html

相关文章

  • pipenv 更优雅的管理你的python开发环境

    摘要:可通过以下命令生成文件运行虚拟环境可使用以下命令来运行项目或者启动虚拟环境的环境直接运行并不会出现命令行,是应为没有配置环境变量。 本文最早发布与个人博客:http://www.pylixm.cc 最近常看到pipenv这个管理工具,今天有时间查了下,是 Kennethreitz 大神的作品,看了下github的仓库,是2017年1月份创建的,仅仅一年的时间变获得了7k+的收藏,最新一...

    dockerclub 评论0 收藏0
  • Pipenv – 超好用的 Python 管理工具

    摘要:安全,广泛地使用校验,能够自动曝露安全漏洞。部分用来设置仓库地址,部分用来指定项目依赖的包,部分用来指定开发环境需要的包,这样分开便于管理。参考链接新款虚拟环境工具详解笔记使用指南官方推荐的包管理工具 pipenv 是什么 pipenv 是 python 官方推荐的包管理工具,集成了 virtualenv、pyenv 和 pip 三者的功能于一身,类似于 php 中的 composer...

    tunny 评论0 收藏0
  • 比virtuslenv更好用的虚拟环境pipenv

    摘要:提示如果你对的用法以及虚拟环境的概念不熟悉的话,可以通过专栏的旧文出发之旅进行简单的认识。为什么使用会自动帮你管理虚拟环境和依赖文件,并且提供了一系列命令和选项来帮助你实现各种依赖和环境管理相关的操作。 什么是Pipenv Pipenv是Kenneth Reitz在2017年1月发布的Python依赖管理工具,现在由PyPA维护。你可以把它看做是pip和virtualenv的组合体,而...

    wing324 评论0 收藏0
  • 快速入门Python 最新最流行的pipenv虚拟环境

    摘要:的把最新型最先进的虚拟环境吵得火热。进入后,你会发现用也是能生效的。但是注意进入环境后千万不要用退出,而应该用退出。最佳解决方案是因为这种在其他地方也常见,一般都是没有在环境里安装的问题。 2018的PyCon把最新型最先进的Python虚拟环境pipenv吵得火热。看了下介绍感觉真的很好用,它在virtualenv的基础上包装了一些更便捷的功能,解决了很多很多virtualenv欠缺...

    roundstones 评论0 收藏0
  • Python小世界:项目虚拟环境配置的N种方法

    摘要:三个常用的虚拟环境配置来汇总,如有不适之处,还望各位大佬指正。一个项目对应一个,支持开发环境与正式环境区分。其使用创建环境,以便分隔使用不同版本和不同程序包的项目。 前言 和其他大多数现代编程语言一样,Python对包和 模块的下载、存储以及管理有其自己的一套方法。但是当我们同时开发多个项目工程的时候,不同的项目会将第三方的包存放在相同的路径下。这就意味着,如果有两个工程依赖同一个包,但是所...

    kidsamong 评论0 收藏0

发表评论

0条评论

whidy

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<