title: Ubuntu 21.04, Virtualenv and its configuration of Python
body: <p><strong>EDIT:</strong></p>
  <ul>
  <li>In addition to the behaviour outlined below, the Python3.10 based environment seems to be ignoring packages installed with the <code>pip -e</code> option (<strong>development mode</strong>).</li>
  <li>Specifically, a package installed in development mode is not listed in <code>pip freeze</code> (which, it does in the Python3.9 based virtual environment) and a simple <code>import &lt;package_name&gt;</code> fails. If the package is installed normally (i.e. <strong>not</strong> in development mode) everything works as expected.</li>
  </ul>
  <hr />
  <p>I am using <code>virtualenv</code> to create a virtual environment based around Python 3.10. While <code>virtualenv</code> finishes without errors and does seem to activate, it still fails to pick up its own Python <strong>unless</strong> the <code>PYTHONPATH</code> environment variable has been set manually.</p>
  <p>I am not sure if the situation I am faced with is due to Ubuntu's way of incorporating Python or the way virtualenv is setting up the environment so that it picks up a local interpreter. Here is what I have gathered this far:</p>
  <ol>
  <li><p>My base system is an Ubuntu 21.04. It has its own Python 3 (Python3.9.5) installation which I have not touched at all except installing the <code>python3-virtualenv</code> package using <code>apt</code>.</p>
  </li>
  <li><p>With Python 3.10, I installed the <code>python3.10-dev</code> package and proceeded to create a virtual environment in the usual way:</p>
  <ol>
  <li><code>&gt; virtualenv -p python3.10 the_env/</code></li>
  <li><code>&gt; source the_env/bin/activate</code></li>
  </ol>
  </li>
  <li><p>Although this looks OK so far, this environment does not have <strong>any</strong> information about its own <code>site-packages</code> directory. Not even the one that <code>virtualenv</code> is supposed to be creating which includes <code>pip</code>. In this installation, if you try to <code>&gt; pip --version</code> you simply get an error that
  the <code>pip</code> package does not exist (the <code>pip</code> &quot;executable&quot; location is picked up correctly, but because the interpreter does not know anything about its <code>site-packages</code> it fails to start pip properly).</p>
  </li>
  </ol>
  <p>Long story short, I created two environments, one based on Python3.9 (which works perfectly) and one based on Python3.10 (which does not work) and did a very simple test in <strong>each</strong> environment:</p>
  <ul>
  <li><code>&gt; python -m site</code>
  <ul>
  <li>On the Python3.9 environment, <code>sys.path</code> <strong>includes</strong> a path that leads all the way to this particular environment's <code>site-packages</code></li>
  <li>On the Python3.10 environment, <code>sys.path</code> <strong>does not</strong> include that particular path but still includes the typical paths you expect to find (e.g. those pointing to the interpreter itself and the top environment directory but <strong>not</strong> the specific path that points to the <code>site-packages</code> location.</li>
  </ul>
  </li>
  </ul>
  <p>Following this, I defined a <code>PYTHONPATH</code> <em>manually</em>, before activating the environment which points exactly to the <code>site-packages</code> for that particular environment and everything worked as expected.</p>
  <p>I <em>suspect</em> that this might be something to do with the fact that my system's Python is 3.9 which means that the <code>USER_SITE</code> variable <strong>is</strong> valid while in the case of Python3.10, it is not (because, I do not have a use for it, this is just a virtual environment I am creating). So, I <em>suspect</em> that this might be throwing off the way the <a href="https://docs.python.org/3/library/site.html" rel="nofollow noreferrer"><code>site</code> module determines where things are</a>.</p>
  <p>As I am not sure, I would like to ask the following:</p>
  <ol>
  <li><p>Could this be something to do with the way Ubuntu handles the Python installation that might just be creating this small problem with virtual environments?</p>
  </li>
  <li><p>Could the problem be with <code>virtualenv</code> that does not explicitly specify a <code>PYTHONPATH</code>?</p>
  </li>
  <li><p>Could this behaviour be something of a corner case of the <code>site</code> module?</p>
  </li>
  </ol>