3 ms·
You can try https://github.com/jaraco/pip-run https://github.com/jaraco/pip-run or https://github.com/PyAr/fades https://github.com/PyAr/fades (or eventually pi
by networked 3y ago
You can try https://github.com/jaraco/pip-run https://github.com/jaraco/pip-run or https://github.com/PyAr/fades https://github.com/PyAr/fades (or eventually pipx: https://github.com/pypa/pipx/issues/913 https://github.com/pypa/pipx/issues/913). They don't require a build step.
For example,
#! /usr/bin/env -S pip-run Jinja2==3.*
from jinja2 import Environment
env = Environment(autoescape=True)
template = env.from_string("Hello, {{ name }}!")
print(template.render(name="world"))
There is a downside. Because pip-run recreates the virtualenv every time, the script takes a second to start up. pipx will cache virtualenvs once the single-file script feature is released. I haven't used fades yet.
Edit: fades caches virtualenvs.
#! /usr/bin/env fades
from jinja2 import Environment # fades Jinja2==3.*
env = Environment(autoescape=True)
template = env.from_string("Hello, {{ name }}!")
print(template.render(name="world"))