installation psycopg2 on MAC with error: pg_config executable not found - postgresql

I need your help with installation psycopg2 on MAC.
I've already installed:
Python 3.7.3 as a part of Anaconda environment
Postgres.app from https://postgresapp.com
When I'm trying to install psycopg2 package a terminal show me an error
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. 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'.
I've read a number of articles where they recommend to provide $PATH before installing psycopg2, but the problem is in a fact that Postgres.app doesn't create the pg_config directory:
/Users/konstantin_klychkov/Library/Application Support/Postgres/var-12

the problem is in a fact that Postgres.app doesn't create pg_config directory:
/Users/konstantin_klychkov/Library/Application Support/Postgres/var-12
I think you may be looking in the wrong place. pg_config is not a directory, but a program. Try putting /Applications/Postgres.app/Contents/Versions/12/bin in your $PATH:
$ ls /Applications/Postgres.app/Contents/Versions/12/bin | grep pg_config
pg_config

Related

Installing matplotlib / basemap on Azure Databricks

Working on POC with netCDF(.nc) files. Would like do some visualisation and while trying to install Basemap having some issues.
As per the pre-requisites, got numpy and matplotlib installed.
geos is already installed
When installing basemap from git %sh pip install pip install --user git+https://github.com/matplotlib/basemap.git getting below error.
Collecting git+https://github.com/matplotlib/basemap.git
Cloning https://github.com/matplotlib/basemap.git to /tmp/pip-req-build-w20pcpms
Running command git clone -q https://github.com/matplotlib/basemap.git /tmp/pip-req-build-w20pcpms
ERROR: Command errored out with exit status 1:
command: /databricks/python3/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-w20pcpms/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-w20pcpms/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-w20pcpms/pip-egg-info
cwd: /tmp/pip-req-build-w20pcpms/
Complete output (18 lines):
checking for GEOS lib in /root ....
checking for GEOS lib in /root/local ....
checking for GEOS lib in /usr ....
checking for GEOS lib in /usr/local ....
checking for GEOS lib in /sw ....
checking for GEOS lib in /opt ....
checking for GEOS lib in /opt/local ....
Can't find geos library in standard locations ('/root', '/root/local', '/usr', '/usr/local', '/sw', '/opt', '/opt/local').
Please install the corresponding packages using your
systems software management system (e.g. for Debian Linux do:
'apt-get install libgeos-3.3.3 libgeos-c1 libgeos-dev' and/or
set the environment variable GEOS_DIR to point to the location
where geos is installed (for example, if geos_c.h
is in /usr/local/include, and libgeos_c is in /usr/local/lib,
set GEOS_DIR to /usr/local), or edit the setup.py script
manually and set the variable GEOS_dir (right after the line
that says "set GEOS_dir manually here".
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Depending on your runtime version you may be pointing at the wrong version of python (I'm assuming python 3) with your pip commands. Also, if you're installing python packages through pip inside of a notebook environment you're going to have a bad time. The best way to install through pip on a cluster is to use an init script.

Installing python program in AWS Elastic Beanstalk with Postgresql gives pg_config error

I've created a python application which uses Postgresql. I used psycopg2 library (v 2.8.4) when doing the development, but when trying to install it on the beanstalk, it gives the following error:
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. 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'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<http://initd.org/psycopg/docs/install.html>).
Anyone have idea how to solve this?
Found the answer to the question. Instead of installing the psycopg2 directly, use psycopg2-binary==2.8.4.
Similar question is also being asked here

How to install psycopg2, fro linux, Fedora

There are errors when I try to install psycopg2
pip install psycopg2
I don't know whether I have pg_config or not. I tried these to find out where is pg_config, psql. but I don't understand how pg_config is not in the system when I have installed PostgreSQL(11.4). And if it is there in the system how to set the PATH so that psycopg2 installation is possible.
(myvenv) [jpsofficedev#localhost djangogirls]$ postgres --version
postgres (PostgreSQL) 11.4
(myvenv) [jpsofficedev#localhost djangogirls]$ echo $PATH
/home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin:/home/jpsofficedev/.local/bin:/home/jpsofficedev/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/Library/PostgreSQL/11.4/bin
(myvenv) [jpsofficedev#localhost djangogirls]$ which psql
/usr/bin/psql
(myvenv) [jpsofficedev#localhost djangogirls]$ which pg_config
/usr/bin/which: no pg_config in (/home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin:/home/jpsofficedev/.local/bin:/home/jpsofficedev/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/Library/PostgreSQL/11.4/bin)
Collecting psycopg2
Using cached https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz
ERROR: Command errored out with exit status 1:
command: /home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-w3r253fu/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-w3r253fu/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /tmp/pip-install-w3r253fu/psycopg2/
Complete output (23 lines):
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. 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'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<http://initd.org/psycopg/docs/install.html>).
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.2, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
This worked for me
sudo yum install python-devel postgresql-devel rpm-build
pip install psycopg2
As per suggested by one of the users, I used these commands and it worked for me.
sudo dnf install python-devel postgresql-devel rpm-build
pip install psycopg2
OP put this as a comment. It also worked for me. It would be best if you added this as an answer.
sudo yum install libpq-devel python-devel

How to install psycopg2 on windows 7

I have tried pip install psycopg2 and following errors i got:
Error:
(ScrapeProj) C:\Users\e2sn7cy\Documents\GitHub\scraper>pip install psycopg2==2.5.4
Collecting psycopg2==2.5.4
Using cached psycopg2-2.5.4.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info\psycopg2.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
writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.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 c:\users\e2sn7cy\appdata\local\temp\pi
p-build-joij3x\psycopg2
Then I tried using easy_install by downloading the .exe file from Stickpole and I got following errors :
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj\Scripts>easy_install psycopg2-2.6.1.win-amd64-py2.7-pg9
.4.4-release.exe
Processing psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe
psycopg2.tests.test_module: module references __file__
psycopg2.tests.test_types_basic: module references __file__
creating 'c:\users\e2sn7cy\appdata\local\temp\easy_install-sa7asq\psycopg2-2.6.1-py2.7-win32.egg' and
adding 'c:\users\e2sn7cy\appdata\local\temp\easy_install-sa7asq\psycopg2-2.6.1-py2.7-win32.egg.tmp'
to it
creating c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Extracting psycopg2-2.6.1-py2.7-win32.egg to c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages
Adding psycopg2 2.6.1 to easy-install.pth file
Installed c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Processing dependencies for psycopg2==2.6.1
Finished processing dependencies for psycopg2==2.6.1
But when I again tried to install through pip I am getting a new message that its already there :
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj>pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in c:\users\e2sn7cy\envs\scrapepro
j\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Then I thought ok I should try to import and then I got this error:
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\e2sn7cy\Envs\ScrapeProj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg\psycopg2\__
init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: %1 is not a valid Win32 application.
Now I am not able to understand what to do. Thanks
Edit 1:
I have also added my PostgreSQL path to system path variables
path:C:\Program Files\PostgreSQL\9.4
path:C:\Program Files\PostgreSQL\9.4\bin
The correct answer was given by Craig Ringer, I am just adding this because I came to know that we should first check which version of 64 bit or 32bit Python installed on our system. If you have 32 bit version of Python and if you will try to install 64bit, then you will get the above error on importing.
For checking the version:
import platform
platform.architecture()
and you will get an output like this:
('32bit','WindowsPE')
Download the pre-packaged binary release of psycopg2 for Windows rather than compiling it yourself. It's a pain to compile on Windows. This is explained in the install documentation for psycopg2.
You might need to remove your half-installed attempts.
Choose the appropriate version from this page:
http://www.stickpeople.com/projects/python/win-psycopg/
Right click and select copy link address
Back at home, use easy_install <<Paste URL Here>>
Freeze your new requirements: pip freeze > requirements.txt
Now that psycopg is in PyPI (as of March 2017 it appears), just fire up a command prompt with administrator privileges and install like so:
python -m pip install -U pip
python -m pip install psycopg2
If you don't have pip installed, follow the instructions here to do that first:
https://stackoverflow.com/a/12476379/2540707
pip install psycopg2-binary
This worked for me
Step 1: Compilers Installation and configuration
https://wiki.python.org/moin/WindowsCompilers
Before do anything, install or upgrade the Setuptools Python package. It contain compatibility improvements and add automatic use of compilers:
pip install --upgrade setuptools
Step 2: Download and install PostgreSQL
Before you continue to install python packages inside you virtualenvs download postgres itself. It contains files that are needed when compiling the psycopg2 python package. Just use the PostgreSQL installer(version 10 for example).
Important: add the postgres C:\Program Files\PostgreSQL\10\bin folder to your path. It contains the .dll needed for psycopg2.
Step 3: Install psycopg2
pip install psycopg2
Tested on Windows 7 + python 3.7
The best/easiest way of installing packages (including this problematic psycopg2 ) for python on windows platform is to:
1) install anaconda and ...
2) use Anaconda Navigator GUI to install/update packages.
By this one avoids many inconsistencies and conflicts that occurs among different packages versions and installations.

install pg_config in CentOS 5.5 without yum

python version 2.4
# pip install psycopg2
Getting the following error:
Downloading/unpacking psycopg2
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 /root/sources/build/psycopg2
Storing complete log in /root/.pip/pip.log
[root#host sources]# which pg_config
/usr/bin/which: no pg_config in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/b in:/root/bin)
I am unable to install pg_config as an executable
You need to install postgresql-devel package.
Or build Postgres from source and then you'll have pg_config not from a package.
For AWS linux (or RedHat for that matter) use:
sudo yum install postgresql-devel
The above answer is correct: you need to install the -devel package. Furthermore, I found via this comment that you then might need to manually specify where to look for pg_config to build psycopg2.
In particular, I wound up running
python2.7 setup.py build_ext --pg-config /usr/pgsql-9.3/bin/pg_config install
Note that this path will depend on your postgres version.