psycopg: Python.h: No such file or directory

后端 未结 4 1428
野性不改
野性不改 2021-01-07 16:34

I\'m compiling psycopg2 and get the following error: Python.h: No such file or directory

How to compile it, Ubuntu12 x64.

相关标签:
4条回答
  • 2021-01-07 16:48

    Python 2:

    sudo apt-get install python-dev
    

    Python 3:

    sudo apt-get install python3-dev
    
    0 讨论(0)
  • 2021-01-07 16:48

    This is a dependency issue.

    I resolved this issue on Ubuntu using apt-get. Substitute it with a package manager appropriate to your system.

    For any current Python version:

    sudo apt-get install python-dev
    

    For alternative Python version:

    sudo apt-get install python<version>-dev
    

    For example 3.5 as alternative:

    sudo apt-get install python3.5-dev
    
    0 讨论(0)
  • 2021-01-07 16:55

    As mentioned in psycopg documentation http://initd.org/psycopg/docs/install.html

    Psycopg is a C wrapper around the libpq PostgreSQL client library. To install it from sources you will need:

    • C compiler
    • Python header files

    They are usually installed in a package such as python-dev a message error such: Python.h: no such file or directory indicate that you missed mentioned python headers.

    How you can fix it? First of all you need check which python version installed in your virtual envitonment or in system itself if you didnt use virtual environment. You can check your python version by:

    python --version 
    

    After it you should install the same python-dev version which installed on your virtual env or system. For example if you use python3.7 you should install

    apt-get install python3.7-dev 
    

    Hope my answer will help anyone

    0 讨论(0)
  • 2021-01-07 17:10

    if you take a look at PostgreSQL's faq page ( http://initd.org/psycopg/docs/faq.html ) you'll see that they recommend installing pythons development package, which is usually called python-dev. You can install via

    sudo apt-get install python-dev

    0 讨论(0)
提交回复
热议问题