title: Cannot install psycopg2 Ubuntu
body: <p>Trying to get a server ready for a django project and I'm running into some issues with setup for postgres.</p>
  
  <p>I'm following this guide:
  <a href="https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html" rel="noreferrer">https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html</a></p>
  
  <p>And I'm at step 5:</p>
  
  <blockquote>
    <ol start="5">
    <li>Now, we need to configure postgreSQL so that it can communicate with our Django application. For this, install psycopg2 database
    adapter. But this adapter have some package dependencies, so first
    install them.</li>
    </ol>
    
    <p>run:</p>
    
    <p>(django_env) $ sudo apt-get install libpq-dev python3-dev</p>
    
    <p>then...</p>
    
    <p>(django_env) $ pip install psycopg2</p>
  </blockquote>
  
  <p>I do that, and this point in the instructions, I get a "compilation failed" error.</p>
  
  <p>I tried the solutions suggested in this stack exchange question:
  <a href="https://stackoverflow.com/questions/24157533/trouble-with-psycopg2-in-virtualenv-python3-for-use-with-django">Trouble with psycopg2 in virtualenv python3 for use with Django</a>
  and this one:
  <a href="https://stackoverflow.com/questions/27195490/cannot-install-psycopg2-on-virtualenv">Cannot install psycopg2 on virtualenv</a></p>
  
  <p>I am very much a linux and django noob, so if this is a duplicate issue, please have mercy on me and leave a comment explaining why you are marking it as a duplicate as you do so. </p>
  
  <p>Thanks for your time!</p>
  
  <p>Here's the output and install command that caused it:</p>
  
  <pre><code>(django_env1) user:/home/projects/sample_project$ sudo pip install psycopg2
  Downloading/unpacking psycopg2
    Downloading psycopg2-2.7.3.2.tar.gz (425kB): 425kB downloaded
    Running setup.py (path:/tmp/pip_build_root/psycopg2/setup.py) egg_info for package psycopg2
  
  Installing collected packages: psycopg2
    Running setup.py install for psycopg2
      building 'psycopg2._psycopg' extension
      x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.3/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement
      In file included from psycopg/psycopgmodule.c:27:0:
      ./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory
       #include &lt;Python.h&gt;
                          ^
      compilation terminated.
      error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
      Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-_0zc1L-record/install-record.txt --single-version-externally-managed --compile:
      running install
  
  running build
  
  running build_py
  
  creating build
  
  creating build/lib.linux-x86_64-2.7
  
  creating build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/_ipaddress.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/tz.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/_json.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/__init__.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/errorcodes.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/psycopg1.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/_range.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/extensions.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/sql.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/pool.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  copying lib/extras.py -&gt; build/lib.linux-x86_64-2.7/psycopg2
  
  creating build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_bug_gc.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_psycopg2_dbapi20.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_types_extras.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_async_keyword.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_sql.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_ipaddress.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/dbapi20.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_fast_executemany.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/__init__.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_copy.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_with.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_connection.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_module.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_replication.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_extras_dictcursor.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_dates.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_bugX000.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/testconfig.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_errcodes.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_transaction.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_async.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/testutils.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_cursor.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_quote.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/dbapi20_tpc.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_notify.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_lobject.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_cancel.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_green.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  copying tests/test_types_basic.py -&gt; build/lib.linux-x86_64-2.7/psycopg2/tests
  
  running build_ext
  
  building 'psycopg2._psycopg' extension
  
  creating build/temp.linux-x86_64-2.7
  
  creating build/temp.linux-x86_64-2.7/psycopg
  
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.3/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement
  
  In file included from psycopg/psycopgmodule.c:27:0:
  
  ./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory
  
   #include &lt;Python.h&gt;
  
                      ^
  
  compilation terminated.
  
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  
  ----------------------------------------
  Cleaning up...
  Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-_0zc1L-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/psycopg2
  </code></pre>