“Failed building wheel for psycopg2” - MacOSX using virtualenv and pip

前端 未结 14 1594
囚心锁ツ
囚心锁ツ 2020-12-08 18:20

I\'m attempting to make a website with a few others for the first time, and have run into a weird error when trying to use Django/Python/VirtualEnv. I\'ve found solutions to

14条回答
  •  醉话见心
    2020-12-08 19:16

    TDLR

    If you aren't used to installing Python C-extensions, and psycopg2 isn't a core part of your work, try

    pip install psycopg2-binary
    

    Building Locally

    psycopg2 is a C-extension, so it requires compilation when being installed by pip. The Build Prerequisites section of the docs explain what must be done to make installation via pip possible. In summary (for psycopg 2.8.5):

    • a C compiler must be installed on the machine
    • the Python header files must be installed
    • the libpq header files must be installed
    • the pg_config program must be installed (it usually comes with the libpq headers) and on $PATH.

    With these prerequisites satisfied, pip install psycopg2 ought to succeed.

    Installing pre-compiled wheels

    Alternatively, pip can install pre-compiled binaries so that compilation (and the associated setup) is not required. They can be installed like this:

    pip install psycopg2-binary
    

    The docs note that

    The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements.

    but I would suggest that psycopg2-binary is often good enough for local development work if you are not using psycopg2 directly, but just as a dependency.

    Concluding advice

    Read the informative installation documentation, not only to overcome installation issues but also the impact of using the pre-compiled binaries in some scenarios.

提交回复
热议问题