帮助创建和使用pyenv virtualenvs的简单脚本
pyenv-mkenv的Python项目详细描述
pyenv mkenv公司
简化pyenv环境创建;脚本需要python3.6+。在
你用pyenv吗?在
签出新存储库时,工作流如下所示:
pyenv virtualenv $MY_PY_VERSION$MY_REPO_NAME pyenv local$MY_REPO_NAME pip install -U pip pip install -r requirements.txt
一定有更好的办法!在
现在有:
^{pr2}$这个脚本可以做很多事情:
- 选择一个python版本(根据偏好,是最新安装的CPython版本;见下文)
- 默认情况下,使用目录名创建pyenv virtualenv(由
-n
/--name
)控制) - 更新pip
- 安装要求(可提供多个路径)
安装
- 来自PyPI:
pip install pyenv-mkenv
- 来自github:
pip install git+git://github.com/clbarnes/pyenv-mkenv.git
- 开发:
git clone git@github.com:clbarnes/pyenv-mkenv.git && cd pyenv-mkenv && pip install -e .
或者只复制^{
使用
usage: mkenv [-h] [-p] [-n NAME] [-r [REQUIREMENTS]] [-v] [--version] [py_version] positional arguments: py_version Python version. If this option starts with '/', the rest will be interpreted as a regex; otherwise, a simple match to the start of the version name will be used. Empty string by default. By default, mkenv will try to find the highest version matching the string (use -p to see priority and pick) manually) optional arguments: -h, --help show this help message and exit -p, --pick Prompt to select from matching versions -n NAME, --name NAME Name for the environment (defaults to directory name) -r [REQUIREMENTS], --requirements [REQUIREMENTS] Requirements files to install from. If option is used with no path given, user will be prompted. -v, --verbose --version show program's version number and exit
Python版本
pyenv mkenv列出可用的python版本(即$PYENV_HOME/versions/
中的非symlink目录),并对它们进行排序。
排序顺序是为了更直观:
- 更喜欢标准的CPython分布(即以数字开头)
- 更喜欢更高版本(例如,看起来像版本的子字符串是按降序进行解析和排序的)
- 非标准发行版按字典顺序排序,没有版本号,然后按版本号排序(多个版本号,例如pypy3.6-7.3.0,从左到右)
如果没有给出py_version
参数,则选择列表中的第一项。
如果给定了一个字符串,则选择列表中以该字符串开头的第一项(例如3.8 -> 3.8.1
)。
如果给定的字符串以/
开头,则将剩余部分视为在每个版本名中搜索的regex;将使用第一个匹配的名称。在
要确定您得到的是哪个版本,请使用-p
/--pick
选项。
这将显示与py_version
参数匹配的版本(按排序顺序),并允许您选择所需的版本。在
要求
默认情况下,mkenv
不安装任何要求。
但是,可以使用-r
选项添加任意数量的需求文件。
如果-r
不带参数,mkenv
会向下搜索目录树,查找与globrequirements*.txt
匹配的任何内容,忽略隐藏的目录,并提示用户选择要安装的目录。在
免责声明
这不是一个pyenv插件;它是一个python脚本,假设您安装了pyenv。在
- 项目
标签: