A development version of pipx supports a feature that address this pain point. See pull request #916 [1]<p>In your script <i>example.py</i>, you would specify your dependencies in a special comment like this:<p><pre><code> # Requirements:
# requests
import requests
...
</code></pre>
Then you could run the script like this:<p><pre><code> pipx run file:example.py
</code></pre>
This would install the dependencies in a temporary virtual environment, and run the script in that virtual environment.<p>[1] <a href="https://github.com/pypa/pipx/pull/916">https://github.com/pypa/pipx/pull/916</a>