What is the relationship between a python virtual environment and specific system libraries?
<p>We have an application which does some of its work in Python in a python virtual environment setup using virtualenv.</p>

<p>We've hit a problem where the version of a system library does not match the version installed in the virtual environment.  That is we have <code>NetCDF4</code> installed into the virtual environment and and previously had <code>libnetcdf.so.7</code> installed through <code>yum</code>.  The python package appears to be dependent on having <code>libnetcdf.so.7</code> available.</p>

<p>Due to a system update <code>libnetcdf.so.7</code> no longer exists and has been replaced by <code>libnetcdf.so.11</code>.</p>

<p>So the question is this: Does setting up the virtual environment detect the system library version or is there some other mechanism?  Also do we need to re-build the environment to fix this or is there another option?</p>

<p>When you use <code>virtualenv</code> to create a virtual environment you have the option of whether or not to include the standard site packages as part of the environment. Since this is now default behaviour (though it can be asserted by using <code>--no-site-packages</code> in the command line) it's possible that you are using an older version of virtualenv that doesn't insist on this.</p>

<p>In that case you should be able to re-create the environment fairly easily. First of all capture the currently-installed packages in the existing environment with the commmand</p>

<pre><code>pip freeze &gt; /tmp/requirements.txt
</code></pre>

<p>Then delete the virtual environment, and re-create it with the following commands:</p>

<pre><code>virtualenv --no-site-packages envname
source envname/bin/activate
pip install -r /tmp/requirements.txt
</code></pre>

<p>However none of this addresses the tricky issue of not having the required support libraries installed. You might try creating a symbolic link to the new library from the old library's position - it may be that<code>NetCDF4</code> can work with multiple versions of <code>libnetCDF</code> and is simply badly configured to use a specific version. If not then solving thsi issue might turn out to be long and painful.</p>

python linux virtualenv