Stay Hungry,Stay Foolish!

python跨版本包管理方案(pyenv + pipenv)

背景

通过对pyenv的探索,已经掌握pyenv对python多版本的管理方法。

 

同时pyenv可以集成virtualenv,实现多项目需求的独立环境的搭建,

from(https://github.com/pyenv/pyenv-virtualenv)

 

问题是,对于项目的管理, 我们缺少一个依赖的配置清单,类似 node的 package.json

这个可以通过pip freeze来生成requirement.txt文件解决。

但是这个方法,具有一些问题,每次pip install后,需要主动调用pip freeze来更新配置清单。

 

针对这个问题,

于是pipenv闪亮出场

https://pipenv.pypa.io/en/latest/

 

针对新的安装包, 只需要 pipenv install xxx, 就可以将新的文件更新到 pipfile中。

体验跟node的npm类似。

 

于是针对包管理的角度, 我们引入新的python跨版本包管理方案

 

pyenv + pipenv

pyenv -- 跨python版本的os环境管理。

pipenv -- 跨多个项目的运行环境管理。

 

pyenv

https://github.com/pyenv/pyenv

pyenv does...

  • Let you change the global Python version on a per-user basis.
  • Provide support for per-project Python versions.
  • Allow you to override the Python version with an environment variable.
  • Search commands from multiple versions of Python at a time. This may be helpful to test across Python versions with tox.

 

pipenv

https://pipenv.pypa.io/en/latest/

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 Pipfile and Pipfile.lock to separate abstract dependency declarations from the last tested combination.
  • Hashes are used everywhere, always. Security. Automatically expose security vulnerabilities.
  • Strongly encourage the use of the latest versions of dependencies to minimize security risks arising from outdated components.
  • Give you insight into your dependency graph (e.g. $ pipenv graph).
  • Streamline development workflow by loading .env files.

 

posted @ 2020-09-30 13:00  lightsong  阅读(273)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel