奔跑的蛇。在不打包或安装的情况下执行python文件
ferret的Python项目详细描述
Python,不过是跑步。
ferret为python脚本提供了一个新的shebang行,它将依赖项安装到一个新的venv-省去了打包和分发的麻烦。ferret允许您专注于编写所需的代码而不牺牲库。
用法
- 在目标环境中安装ferret:
pip install ferret # Warning: this will work with a python3 venv, but not a virtualenv (as used by pipsi)
- 用这个替换您的shebang行:
#! /usr/bin/env ferret
- 在模块的docstring中声明依赖项:
"""
A helpful description about your module
ferret:
- requests == 2.18.4
"""
当您使用ferret运行脚本时,它会解析文件以获取依赖项声明,并准备一个venv以进行匹配。环境保存在~/.local/ferret/venvs下(您可以安全地删除该文件夹的全部内容)。
示例
一旦您安装了ferret,请将其旋转:
cat>just_a_script.py<<EOF#! /usr/bin/env ferret""" Gets my IP from icanhazip.com ferret: - requests == 2.18.4 """importrequestsresponse=requests.get('http://icanhazip.com')response.raise_for_status()print(response.text())EOFchmod+xjust_a_script.py./just_a_script.py
第一次运行脚本时,ferret将设置一个venv,并在其中安装requests。后续运行将重用该环境。