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
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
I was also getting same error. Using Python 3.7.3 and pip 19.1.1.
I used following command.
pip install psycopg2-binary==2.8.3
For MacOS users
After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :
brew install openssl
if you don't have it already.LIBRARY_PATH
: export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
pip3 install psycopg2
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
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.
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
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):
libpq
header files must be installedpg_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.
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.
Read the informative installation documentation, not only to overcome installation issues but also the impact of using the pre-compiled binaries in some scenarios.