Lightweight virtualenv orchestration
Credit to the nox project for much of the implementation.
pip install --user xox
Before you import any other third-party modules, call xox.activate():
import xox xox.activate("lxml", "requests>=1.0") import lxml import requests
This will create a virtualenv, install packages, and call os.exec() to replace the current process. The virtualenv will be re-used in subsequent runs.
You could also pass python='pythonX.Y' to specify a Python version, or silent=False to show output from pip.
… And that’s it! No custom executables or config files needed, just an extra header in your script.
Any code before your activate() call will be run twice: once without and once within the virtualenv. Any code after your activate() call will run only within the virtualenv.
Each virtualenv is stored in a subdirectory of system’s temporary directory named 'xox-virtualenvs'. No cleanup mechanism is provided - sorry!
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.