python tool - pg_config executable not found
could it (23)
On alpine, the library containing
postgresql-dev. To install, run:
apk add postgresql-dev
I am having trouble installing psycopg2. I get the following error when I try to
pip install 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'. ---------------------------------------- Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is
pg_config is actually in my
PATH; it runs without any problem:
$ which pg_config /usr/pgsql-9.1/bin/pg_config
I tried adding the pg_config path to the
setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!
Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
But it is actually THERE!!!
I am baffled by these errors. Can anyone help please?
By the way, I
sudo all the commands. Also I am on RHEL 5.5.
This is what worked for me on CentOS, first install:
sudo yum install postgresql postgresql-devel python-devel
On Ubuntu just use the equivilent apt-get packages.
sudo apt-get install postgresql postgresql-dev python-dev
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
I found that this page provided the best instructions for installing PostgreSQL on my mac and that the pip install command worked perfectly afterwards:
sudo yum install postgresql-devel (centos6X)
pip install psycopg2==2.5.2
Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:
My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;
Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:
or for newer version:
Then install psycopg2.
apt-get build-dep python-psycopg2
python-psycopg2 solved it for me on Arch Linux:
pacman -S python-psycopg2
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
pg_config in that app's contents and added the dir to
It was at
/Applications/Postgres.app/Contents/Versions/latest/bin. So this worked:
Try to add it to PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Just solved the problem in Cent OS 7 by:
make sure your PostgreSql version matches the right version above.
for CentOS/RedHat make sure that
/etc/alternatives/pgsql-pg_config is a non-broken symlink
On Linux Mint
sudo apt-get install libpq-dev worked for me.
Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in
When you installed MacPorts, it already added
/opt/local/bin to your PATH.
So, this will fix the problem:
$ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config
pip install psycopg2 will be able to run
pg_config without issues.
You need to upgrade your pip before installing psycopg2. Use this command
pip install --upgrade pip
sudo apt-get install libpq-dev works for me on Ubuntu 15.4
UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr rpm -ivh pgdg-centos91-9.1-4.noarch.rpm yum install postgresql yum install postgresql-devel PATH=$PATH:/usr/pgsql-9.1/bin/ pip install psycopg2
On Gentoo You have to execute the following
# Install postgresql client libraries sudo emerge postgresql-base
Have you installed python-dev? If you already have, try also installing libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv
Just to sum up, I also faced exactly same problem. After reading a lot of posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.
pg_config is in
libpq-dev in Debian/Ubuntu,
libpq-devel on Cygwin/Babun.)
This works for me:
sudo apt-get install libpq-dev python-dev
Due to popular demand,
tqdm has added support for
pandas. Unlike the other answers, this will not noticeably slow pandas down -- here's an example for
import pandas as pd import numpy as np from tqdm import tqdm df = pd.DataFrame(np.random.randint(0, int(1e8), (10000, 1000))) # Create and register a new `tqdm` instance with `pandas` # (can use tqdm_gui, optional kwargs, etc.) tqdm.pandas() # Now you can use `progress_apply` instead of `apply` df.groupby(0).progress_apply(lambda x: x**2)
To directly answer the original question, replace:
from tqdm import tqdm tqdm.pandas() df_users.groupby(['userID', 'requestDate']).progress_apply(feature_rollup)
Note: tqdm <= v4.8:
For versions of tqdm below 4.8, instead of
tqdm.pandas() you had to do:
from tqdm import tqdm, tqdm_pandas tqdm_pandas(tqdm())