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

前端 未结 14 1508
囚心锁ツ
囚心锁ツ 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:08

    For MacOS users, this question has the correct solution:

    install command line tools if necessary:

    xcode-select --install

    then

    env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

    0 讨论(0)
  • 2020-12-08 19:12

    I was also getting same error. Using Python 3.7.3 and pip 19.1.1.

    error screen

    I used following command.

    pip install psycopg2-binary==2.8.3
    
    0 讨论(0)
  • 2020-12-08 19:13

    For MacOS users

    After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :

    • Install openssl with brew install openssl if you don't have it already.
    • add openssl path to LIBRARY_PATH :
    export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
    
    • install psycopg2 with pip pip3 install psycopg2
    0 讨论(0)
  • 2020-12-08 19:14

    For Mac OS X users:

    1. First check your postgresql path by running this command in terminal:

    pg_config
    

    If this fails lookup how to add pg_config to your path.

    2. Next install Xcode Tools by running this command in terminal:

    xcode-select --install
    

    If you have both those sorted out now try to install psycopg2 again

    0 讨论(0)
  • 2020-12-08 19:14

    Is your error message complete? the most encountered reason for failing to install psycopg2 on mac from pip is pg_config is not in path. by the way, using macports or fink to install psycopg2 is more recommended way, so you don't have to worry about pg_config, libpq-dev and python-dev.

    plus, are using Python 3.5? then upgrage your wheel to > 0.25.0 using pip.

    0 讨论(0)
  • 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.

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