title: How to reset Python environment to its initial empty state?
body: <p>This question is similar to <a href="https://askubuntu.com/q/173323/448153">How do I detect and remove Python packages installed via <code>pip</code>?</a> on AskUbuntu, but I am looking for a simpler and more basic solution than the ones proposed for that question.  I would also like to understand the structure of Python environment and how it is spread over the system.</p>
  
  <p>I am mostly interested in solutions for Ubuntu Linux and similar systems, but I imagine that solutions for Mac OS or maybe even for Windows should not be very different.</p>
  
  <p>I would like to reset my Python environment to the initial empty state without reinstalling my OS (Ubuntu). However, I do not want to touch any parts of the environment installed with the OS package manager (<code>apt</code>). Well, I have not installed any Python packages with <code>apt</code> anyway.  In practice, this means I want to remove and purge all packages installed with <code>pip</code> and all the artefacts they might have left on the system.</p>
  
  <p>It looks like an appropriate solution might be the one mentioned in <a href="https://askubuntu.com/q/173323/448153#comment1259699_259747">this comment</a>:</p>
  
  <pre class="lang-bash prettyprint-override"><code>sudo rm -r /usr/local/lib/python3.5
  </code></pre>
  
  <p>Will this really remove everything?  What about executable scripts (or binaries) installed as parts of Python packages?</p>
  
  <p>Suppose now that I didn't use <code>pip</code> with <code>sudo</code> and installed all my Python packages with <code>pip install --user</code>.  What would be the way to remove them completely in this case?</p>
  
  <p>I did not use <code>virtualenv</code>.</p>
  
  <hr>
  
  <p>These were my main general questions, but they come from a more specific one.  I have encountered an error when using <code>matplotlib</code>, and from the error messages it seems like Python is complaining about missing <code>matplotlib.externals</code> module.  Indeed:</p>
  
  <pre class="lang-python prettyprint-override"><code>import matplotlib.externals
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ImportError: No module named 'matplotlib.externals'
  </code></pre>
  
  <p>There was a <a href="https://github.com/matplotlib/matplotlib/issues/5633/" rel="nofollow noreferrer">similar issue</a> reported "against" <code>matplotlib</code> (just kidding), which was apparently caused my multiple conflicting versions of <code>matplotlib</code>.  However, in my case, even if I do <code>rm -r /usr/local/lib/python3.5</code> and reinstall <code>matplotlib</code>, the error is reproduced.  I did not use Anaconda.</p>