title: In a python environment, how to import a package from a specific version?
body: <p><strong>This is not a duplicate of the question:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/35600492/import-python-packages-with-different-versions-installed">Import python packages with different versions installed</a></p>
  
  <p><strong>Nor can it be solved by virtualenv/pipenv</strong>: packages that share the same name/path but has different code/version <strong>must be installed under the same environment for the program to function properly</strong></p>
  
  <p>Considering the following classic diamond dependency problem:</p>
  
  <ul>
  <li>program &lt;- feature_A &lt;- library (v 1.0)</li>
  <li>program &lt;- feature_B &lt;- library (v 2.0)</li>
  </ul>
  
  <p>Assuming we have full access over the sourcecode of packages 'program', 'feature_A', and 'feature_B', and both feature_A and feature_B has the following code:</p>
  
  <pre><code>import library.*
  </code></pre>
  
  <p>In a conventional package manager like virtualenv, pip and conda, The above situation will preclude feature_A and feature_B from being used in the same project. However since python is an interpretive language, and we can use the source code of feature_A and feature_B. It should be possible to do the following things:</p>
  
  <ol>
  <li><p>ingest the package source/byte codes of both <code>library (v1.0)</code> and <code>library (v2.0)</code>, generate 2 cryptographic hash for each, and install them under 2 different paths that depends on their respective hashes.</p></li>
  <li><p>use a code generator to rewrite <code>feature_A</code> and <code>feature_B</code> such that they import from new paths that depends on cryptographic hashes, and install the rewritten versions.</p></li>
  <li><p>use the code generator to rewrite <code>program</code> such that it imports from the new paths where the rewritten <code>feature_A</code> and <code>feature_B</code> are installed.</p></li>
  </ol>
  
  <p>Now my question is: how difficult it is to fully automate this process? Is a weak artificial intelligence required? Or it can be accomplished using pure functional logic?</p>