Cómo instalar psycopg2 con" pip " en Python?
Estoy usando virtualenv
y necesito instalar "psycopg2".
He hecho lo siguiente:
pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Y tengo los siguientes mensajes:
Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
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
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
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log
Mi pregunta, ¿solo necesito hacer esto para que el psycopg2 funcione?
python setup.py build_ext --pg-config /path/to/pg_config build ...
26 answers
He encontrado este post buscando una solución Linux para este problema.
Este post de "goshawk" me dio la solución: ejecute sudo apt-get install libpq-dev python-dev
si está en Ubuntu/Debian.
Actualizar
Dado que más personas han encontrado esta respuesta útil y publicado sus propias soluciones, aquí hay una lista de ellos:
Debian/Ubuntu
Python 2
sudo apt install libpq-dev python-dev
Python 3
sudo apt install libpq-dev python3-dev
Adicional
Si ninguna de las anteriores resuelve su problema, try
sudo apt install build-essential
O
sudo apt install postgresql-server-dev-all
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-06 15:22:27
En CentOS, necesita los paquetes postgres dev:
sudo yum install python-devel postgresql-devel
Esa fue la solución en CentOS 6 al menos.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-23 09:21:52
En Mac Mavericks con Postgres.app version 9.3.2.0 RC2 Necesitaba usar el siguiente código después de instalar Postgres:
sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-22 01:51:34
Si estás en un mac puedes usar homebrew
brew install postgresql
Y todas las demás opciones están aquí: http://www.postgresql.org/download/macosx/
Buena suerte
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-31 16:26:26
Recientemente configuré psycopg2 en una máquina Windows. La instalación más fácil es usar un binario ejecutable de Windows. Puede encontrarlo en http://stickpeople.com/projects/python/win-psycopg/.
Para instalar el binario nativo en un entorno virtual, use easy_install:
C:\virtualenv\Scripts\> activate.bat
(virtualenv) C:\virtualenv\Scripts\> easy_install psycopg2-2.5.win32-py2.7-pg9.2.4-release.exe
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-01 20:52:27
Para Python 3 debería usar sudo apt-get install libpq-dev python3-dev
en Debian.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-03 18:39:02
Esto es lo que funcionó para mí (En RHEL, CentOS:
sudo yum install postgresql postgresql-devel python-devel
Y ahora incluya la ruta a su directorio binario de postgresql con su instalación pip:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Asegúrese de incluir la ruta correcta. Eso es todo:)
ACTUALIZACIÓN: Para python 3, instale python3-devel
en lugar de python-devel
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-22 23:29:58
Si utiliza Mac OS, debe instalar PostgreSQL desde el origen. Una vez finalizada la instalación, debe agregar esta ruta usando:
export PATH=/local/pgsql/bin:$PATH
O puedes añadir el camino así:
export PATH=.../:usr/local/pgsql/bin
En su archivo .profile
o archivo .zshrc
.
Esto puede variar según el sistema operativo.
Puede seguir el proceso de instalación desde http://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-02 07:22:06
Las respuestas hasta ahora se parecen demasiado a recetas mágicas. El error que recibió le dice que pip no puede encontrar una parte necesaria de la biblioteca de consultas PostgreSQL. Posiblemente esto se debe a que lo tiene instalado en un lugar no estándar para su sistema operativo, por lo que el mensaje sugiere usar la opción --pg-config.
Pero una razón más común es que no tiene libpq instalado en absoluto. Esto sucede comúnmente en máquinas donde no tiene instalado PostgreSQL server porque solo desea ejecutar aplicaciones cliente, no el propio servidor. Cada OS / distro es diferente, por ejemplo en Debian / Ubuntu necesita instalar libpq-dev. Esto le permite compilar y enlazar código con la biblioteca de consultas PostgreSQL.
La mayoría de las respuestas también sugieren instalar una biblioteca de desarrollo de Python. Ten cuidado. Si solo está utilizando el Python predeterminado instalado por su distro, eso funcionará, pero si tiene una versión más reciente, podría causar problemas. Si ha construido Python en esta máquina, entonces ya tiene las bibliotecas de desarrollo necesarias para compilar bibliotecas de C / C++ para interactuar con Python. Mientras esté utilizando la versión pip correcta, la que está instalada en la misma carpeta bin que el binario de python, entonces está todo listo. No es necesario instalar la versión anterior.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-17 19:41:13
On Debian/Ubuntu
:
Primero instale y construya dependencias del paquete psycopg2
:
# apt-get build-dep python-psycopg2
Luego, en su entorno virtual, compile e instale psycopg2
el módulo:
(env)$ pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-06 14:27:15
He hecho esto antes donde en Windows se instala primero en su instalación base de python.
Luego, copie manualmente el psycopg2 instalado en la instalación de virtualenv.
No Es bonito, pero funciona.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-27 03:35:21
Además de instalar los paquetes requeridos, también necesitaba agregar manualmente el directorio bin de PostgreSQL a PATH.$vi ~/.bash_profile
Añádase PATH=/usr/pgsql-9.2/bin:$PATH
antes de export PATH
.$source ~/.bash_profile
$pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-30 09:51:13
En Windows XP se obtiene este error si postgres no está instalado ...
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-14 12:42:47
Instalé Postgresql92 usando el repositorio RedHat / CentOS en el sitio de descargas de PG http://www.postgresql.org/download/linux/redhat /
Para obtener pg_config, tuve que agregar /usr/pgsql-9.2/bin a PATH.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-27 15:24:11
He estado luchando con esto durante días, y finalmente he descubierto cómo conseguir que el comando "pip install psycopg2" se ejecute en un virtualenv en Windows (ejecutando Cygwin).
Estaba golpeando el ejecutable "pg_config no encontrado."error, pero ya había descargado e instalado postgres en Windows. También se instaló en Cygwin; ejecutando "which pg_config" en Cygwin dio "/ usr / bin / pg_config", y ejecutando "pg_config" dio salida sana however sin embargo la versión instalada con Cygwin is:
VERSION = PostgreSQL 8.2.11
Esto no funcionará con la versión actual de psycopg2, que parece requerir al menos 9.1. Cuando agregué "c:\Program Files \ PostgreSQL \ 9.2 \ bin" a mi ruta de Windows, el instalador de pip de Cygwin pudo encontrar la versión correcta de PostgreSQL, y pude instalar correctamente el módulo usando pip. (Esto es probablemente preferible a usar la versión Cygwin de PostgreSQL de todos modos, ya que la versión nativa se ejecutará mucho más rápido).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-26 03:31:43
En Fedora 24: Para Python 3.x
sudo dnf install postgresql-devel python3-devel
sudo dnf install redhat-rpm-config
Activa tu Entorno Virtual:
pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-11 02:09:08
Para los usuarios humildes de Windows se quedaron atascados teniendo que instalar psycopg2 desde el enlace de abajo, simplemente instálelo en cualquier instalación de Python que haya configurado. Colocará la carpeta llamada "psycopg2" en la carpeta site-packages de su instalación de python.
Después de eso, simplemente copie esa carpeta al directorio site-packages de su virtualenv y no tendrá problemas.
Aquí está el enlace que puede encontrar el ejecutable para instalar psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-21 21:33:04
En openSUSE 13.2, esto lo arregló:
sudo zypper in postgresql-devel
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-01 18:19:30
Podría instalarlo en una máquina windows y usando Anaconda / Spyder con python 2.7 a través de los siguientes comandos:
!pip install psycopg2
Luego para establecer la conexión a la base de datos:
import psycopg2
conn = psycopg2.connect(dbname='dbname',host='host_name',port='port_number', user='user_name', password='password')
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-11 11:18:57
En Arch distribuciones base:
sudo pacman -S python-psycopg2
pip2 install psycopg2 # Use pip or pip3 to python3
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-09 09:29:28
Psycopg2 Depende de las Bibliotecas Postgres. En Ubuntu puedes usar:
apt-get install libpq-dev
Entonces:
pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-18 07:36:15
En Ubuntu solo necesitaba el paquete postgres dev:
sudo apt-get install postgresql-server-dev-all
*Probado en un virtualenv
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-04 14:47:29
En OSX 10.11.6 (El Capitan)
brew install postgresql
PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-24 23:35:54
En OSX con macports:
sudo port install postgresql96
export PATH=/opt/local/lib/postgresql96/bin:$PATH
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-17 14:07:24
Si pip no funciona, puede descargarlo .archivo whl desde aquí https://pypi.python.org/pypi/psycopg2
extráigalo..
than python setup.py install
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-23 12:21:30
Prueba esto en Gentoo
:
emerge dev-libs/libpqxx
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-29 12:06:21