Python 3
pip3 install psycopg2 - binary
Run manually command including the path of pg_config
program in PATH
env variable, in my case:
export PATH = /Applications/Postgres.app / Contents / Versions / @latest / bin /: $PATH
and then run
pip3 install psycopg2
Check directory of pg_config
:
which pg_config
You can check for pg_config
presence using the command
which - a pg_config
If you have Postgres installed and the aforementioned command doesn't return anything, you need to manually find the pg_config
executable and put its containing directory in your PATH with:
export PATH = /path/to / postgresql / bin /: $PATH
If the directory is there, you can try to relink postgres with the following command
brew unlink postgresql && brew link postgresql
My issue was that for some reason from within VENV pip install psycopg2 does not work but I found that running this command from inside of VENV
env LDFLAGS = '-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib'
pip install psycopg2
On my MAC, this did the trick:
pip install psycopg2 - binary
$ find / -name pg_config 2 > /dev/null
/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
$
export PATH = $PATH: /Applications/Postgres.app / Contents / Versions / 9.3 / bin /
$ pip install psycopg2
The problem of psycopg2 installation and anycodings_python its import in the .py file can lie in anycodings_python two areas - installation and import.,If your psycopg2 is not getting installed or giving an installation error then check you may have a problem with PostgreSQL installation, linking to pg_config file in the bin folder of PostgreSQL installation or openssl installation and its linkages.,the command will prompt you to Postgres anycodings_python terminal.,I've used both brew and port. Installing anycodings_python any PostgreSQL version through one of anycodings_python them will enable you to build the anycodings_python module.
My error code is:
Running setup.py egg_info
for package psycopg2 Error: pg_config
executable not found.
Please add the directory containing pg_config to the PATH or specify
the full executable path with the option:
python setup.py build_ext--pg - config / path / to / pg_config build...
or with the pg_config option in 'setup.cfg'.Complete output from
command python setup.py egg_info: running egg_info
writing pip - egg - info / psycopg2.egg - info / PKG - INFO
writing top - level names to
pip - egg - info / psycopg2.egg - info / top_level.txt
writing dependency_links to
pip - egg - info / psycopg2.egg - info / dependency_links.txt
warning: manifest_maker: standard file '-c'
not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH or specify the full executable path with the option:
python setup.py build_ext--pg - config / path / to / pg_config build...
or with the pg_config option in 'setup.cfg'.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Command python setup.py egg_info failed with error code 1 in
/Users/sg / build / psycopg2 Storing complete log in
/Users/sg / Library / Logs / pip.log
Python 3
pip3 install psycopg2 - binary
Run manually command including the path anycodings_python of pg_config program in PATH env anycodings_python variable, in my case:
export PATH = /Applications/Postgres.app / Contents / Versions / @latest / bin /: $PATH
and then run
pip3 install psycopg2
Check directory of pg_config:
which pg_config
You can check for pg_config presence anycodings_python using the command
which - a pg_config
If you have Postgres installed and the anycodings_python aforementioned command doesn't return anycodings_python anything, you need to manually find the anycodings_python pg_config executable and put its anycodings_python containing directory in your PATH with:
export PATH = /path/to / postgresql / bin /: $PATH
If the directory is there, you can try anycodings_python to relink postgres with the following anycodings_python command
brew unlink postgresql && brew link postgresql
My issue was that for some reason from anycodings_python within VENV pip install psycopg2 does anycodings_python not work but I found that running this anycodings_python command from inside of VENV
env LDFLAGS = '-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib'
pip install psycopg2
On my MAC, this did the trick:
pip install psycopg2 - binary
Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7,First this: pip install psycopg2-binary and then: pip install psycopg2 worked.,Then, in your virtualenv install psycopg2 with this command:,Is there a way to install django with pip to point to a specific version of python in virtualenv
I was trying so many things and nothing worked. However, if you use Xcode CLI Tools on Mojave and have a problem installing psycopg2, try the following command and try to install psycopg2 again.
sudo installer - pkg / Library / Developer / CommandLineTools / Packages / macOS_SDK_headers_for_macOS_10 .14.pkg - target /
Try this:
pip install psycopg2 - binary
Install postgres
with brew
:
brew install postgres
Then, in your virtualenv install psycopg2
with this command:
ARCHFLAGS = -Wno - error = unused - command - line - argument - hard - error - in - future pip install psycopg2
Just export LDFLAGS before installing it, here is generic command which shall work for OS X (and I believe any LINUX system which has same error):
LDFLAGS = "$(pg_config --ldflags)"
pip install psycopg2
Then, before running pip install psycopg2
, put the binary in your path:
export PATH = $PATH: /Applications/Postgres.app / Contents / Versions / 9.3 / bin
Try installing openssl using brew
brew install openssl
after that export these variables in the terminal.
export LDFLAGS = "-L/usr/local/opt/openssl/lib"
export CPPFLAGS = "-I/usr/local/opt/openssl/include"
verify these variables have been exported by echo $LDFLAGS
and after that you are good to go with installation of psycopg2 by typing
pip3 install psycopg2
You don't seem to have postgres installed, check how to install postgresql in your system, one of the way is brew install postgresql (if you use homebrew- recommended) or download the postgres app from postgresapp.com, pg_config should come with postgres and psycopg2 is trying to find it.,If you use Docker and you do not want to install postgresql in you host system, you can try to use package psycopg2-binary and use postgresql in container.,If you install Postgres in other ways, you need to check that the executable pg_config in in your path.,If you have Postgres installed and the aforementioned command doesn't return anything, you need to manually find the pg_config executable and put its containing directory in your PATH with:
Run manually command including the path of pg_config
program in PATH
env variable, in my case:
export PATH = /Applications/Postgres.app / Contents / Versions / @latest / bin /: $PATH
and then run
pip3 install psycopg2
Check directory of pg_config
:
which pg_config
You can check for pg_config
presence using the command
which - a pg_config
If you have Postgres installed and the aforementioned command doesn't return anything, you need to manually find the pg_config
executable and put its containing directory in your PATH with:
export PATH = /path/to / postgresql / bin /: $PATH
If the directory is there, you can try to relink postgres with the following command
brew unlink postgresql && brew link postgresql
If prerequisites are met, you can install psycopg like any other Python package, using pip to download it from PyPI:,Building Psycopg requires a few prerequisites (a C compiler, some development packages): please check the install and the faq documents in the doc dir or online for the details.,Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection). It was designed for heavily multi-threaded applications that create and destroy lots of cursors and make a large number of concurrent “INSERT”s or “UPDATE”s.,You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:
If prerequisites are met, you can install psycopg like any other Python package, using pip to download it from PyPI:
$ pip install psycopg2
or using setup.py if you have downloaded the source package locally:
$ python setup.py build $ sudo python setup.py install
You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:
$ pip install psycopg2 - binary