title: Fresh install Python 3.9.0 or any other way to fix No module named '_ctypes' error
body: <p>Since installing to Python 3.9.0, I am unable to install any libraries to my virtualenv. When trying to install libraries via pip for example I get:</p>
  <pre><code>$ pip3 install -r requirements.txt
  Collecting anaconda==0.0.1.1
    Using cached anaconda-0.0.1.1.tar.gz (726 bytes)
      ERROR: Command errored out with exit status 1:
       command: /home/jack/dev/37/env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'/tmp/pip-install-01fhtisu/anaconda/setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'/tmp/pip-install-01fhtisu/anaconda/setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' egg_info --egg-base /tmp/pip-pip-egg-info-b71dl332
           cwd: /tmp/pip-install-01fhtisu/anaconda/
      Complete output (11 lines):
      Traceback (most recent call last):
        File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
        File &quot;/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/__init__.py&quot;, line 23, in &lt;module&gt;
          from setuptools.dist import Distribution
        File &quot;/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/dist.py&quot;, line 34, in &lt;module&gt;
          from setuptools import windows_support
        File &quot;/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/windows_support.py&quot;, line 2, in &lt;module&gt;
          import ctypes
        File &quot;/usr/local/lib/python3.9/ctypes/__init__.py&quot;, line 8, in &lt;module&gt;
          from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named '_ctypes'
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  </code></pre>
  <p>I have seen in a few places that this should be fixed by installing <code>libffi-dev</code> then reinstalling python. Here for example: <a href="https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul">Python3: ImportError: No module named &#39;_ctypes&#39; when using Value from module multiprocessing</a></p>
  <p>What is the best way to go about doing this? I am on Ubuntu 20.04 and running <code>python -V</code> outside of a virtualenv reuturns <code>Python 3.9.0</code>.</p>
  <p>To prevent this happening in the future is it generally recommended to only ever install newer versions on python (or any other language) in a venv and not on the system itself?</p>
  <p>Many thanks.</p>