Before PEP 668 – Marking Python base environments as “externally managed”, we used to be able to install python packages globally for each user and use them in any python scripts. This is ugly but extremely convenient to use.
In contrast, using virtualenv is a multi-step process. You have to:
- Setup virtual environment with
virtualenv . - Activate the virtual environment with
source bin/activate - Install any package you need with
pip install <packages>Importantly, step 2 have to be done everytime you need to run your scripts.
Another annoying aspect of virtualenv is that it poop a lot files into the current directory, making your work directory cluttered.
Both of this make python as almost as annoying to use as conventional compiled language even though python is technically a scripting language.
This tool is designed to solve both of the above problems by
- Allowing you to declare your dependencies at the beginning of your python scripts.
- Creating transient virtual environments keyed by the list of dependencies in xdg cache directory.
This goal is that you should be able to just write any python script in a single file and "just run it" as long as you have virtualenv-wrapper installed.
Copy virtualenv-wrapper to somewhere under your PATH.
The code in example.py should provide a simple enough example.
It is possible to execute arbitrary shell command under the created transient
virtual environment by setting the environmental variable
VIRTUALENV_WRAPPER_SETUP.
$ VIRTUALENV_WRAPPER_SETUP='<editor-command>' <script>This can for example be used to execute your editor of choice under the created transient virtual environment such that the python language server will be able to locate installed python packages and provide code completion support.