Reputation: 177
When installing packages with sudo apt-get install or building libraries from source inside a python virtual environment (I am not talking about pip install), does doing it inside a python virtual environment isolate the applications being installed? I mean do they exist only inside the python virtual environment?
Upvotes: 2
Views: 297
Reputation: 60957
Things that a virtual environment gives you an isolated version of:
PATH
entry, so unqualified command-line references to python
, pip
, etc., will refer to the selected Python distribution. This can be convenient if you have many copies of Python installed on the system (common on developer workstations). This means that a shebang line like #!/usr/bin/env python
will "do the right thing" inside of a virtualenv (on a Unix or Unix-like system, at least).site-packages
directory, so Python packages (installed using pip
or built locally inside this environment using e.g. setup.py build
) are installed locally to the virtualenv and not in a system-wide location. This is especially useful on systems where the core Python interpreter is installed in a place where unprivileged users are not allowed to write files, as it allows each user to have their own private virtualenvs with third-party packages installed, without needing to use sudo
or equivalent to install those third-party packages system-wide.... and that's about it.
A virtual environment will not isolate you from:
#!/usr/bin/python
).PATH
(e.g. third party programs or utilities installed via your operating system's package manager)./usr/lib
, /usr/include
, /usr/local/lib
, /usr/local/include
).apt
) rather than a Python package manager (pip
) might not be visible from the the virtualenv's site-packages
folder, but the "native" parts of such packages (in e.g. /usr/lib
) will (probably) still be visible.Upvotes: 2
Reputation: 2903
As per the comment by @deceze, virtual environments have no influence over apt
operations.
When building from source, any compiled binaries will be linked to the python binaries of that environment. So if your virtualenv python version varies from the system version, and you use the system python (path problems usually), you can encounter runtime linking errors.
As for isolation, this same property (binary compatibility) isolates you from system upgrades which might change your system python binaries. Generally we're stable in the 2.x and 3.x, so it isn't likely to happen. But has, and can.
And of course, when building from source inside a virtualenv, installed packages are stashed in that virtualenv; no other python binary will have access to those packages, unless you are manipulating your path or PYTHONPATH in strange ways.
Upvotes: 1