Virtualenvs are a great way to test and develop code in insulated containers. My main use case is to have an insulated environment where I can mock install a package I'm developing and ensure that I've taken care of all the dependencies so that a stranger can use the package as is. The virtualenvwrapper package is a great utility that simplifies managing multiple virtual environments.
One caution I have to observe is that packages installed out side the virtual environment can interfere in ways that make behaviors inside the virtual env very mysterious. For example, before I started using virtual environments seriously I had installed the
Everything installed fine, including an external package
What was happening, is that I was picking up both
As a rule, if you want to use virtual envs, it is best to have a bare install of Python and then not install anything on top of that outside of a virtual environment.
One caution I have to observe is that packages installed out side the virtual environment can interfere in ways that make behaviors inside the virtual env very mysterious. For example, before I started using virtual environments seriously I had installed the
nose
and tox
modules in my base python install. A month or so afterwards I had created a new test environment and was doing pip install -e .
to test whether a package I was writing would install correctly on a fresh environment. Everything installed fine, including an external package
A
my code needed. But, when I went to run nosetests
or tox
my code errored out, claiming package A
had not been installed. BUT I CAN $%#@ SEE IT. LOOK, I TYPE pip list
AND THERE IT IS!What was happening, is that I was picking up both
nose
and tox
from the base environment, which did not have A
installed. I lost some more hair over this. People who know me will confirm that I can't afford such hair loss.As a rule, if you want to use virtual envs, it is best to have a bare install of Python and then not install anything on top of that outside of a virtual environment.
Comments
Post a Comment