Erreur lors de la tentative d’installation de Postgres pour python (psycopg2)

J’ai essayé d’installer psycopg2 dans mon environnement, mais j’obtiens l’erreur suivante:

(venv)avlahop@apostolos-laptop:~/development/django/rhombus-dental$ sudo pip install psycopg2 Downloading/unpacking psycopg2, Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded Running setup.py egg_info for package psycopg2 Installing collected packages: psycopg2 Running setup.py install for psycopg2 building 'psycopg2._psycopg' extension x86_64-linux-gnu-gcc -pthread -fno-ssortingct-aliasing -DNDEBUG -g -fwrapv -O2 -Wall Wssortingct-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x09010D -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.1/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement In file included from psycopg/psycopgmodule.c:27:0: ./psycopg/psycopg.h:30:20: fatal error: Python.h: Δεν υπάρχει τέτοιο αρχείο ή κατάλογος #include  ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Complete output from command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(comstack(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SgfQCA-record/install-record.txt --single-version-externally-managed: running install running build running build_py creating build creating build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/psycopg2 copying lib/pool.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/errorcodes.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/__init__.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/_json.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/_range.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/extensions.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/psycopg1.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/tz.py -> build/lib.linux-x86_64-2.7/psycopg2 copying lib/extras.py -> build/lib.linux-x86_64-2.7/psycopg2 creating build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/testconfig.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copyng tests/test_bug_gc.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_dates.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_copy.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_cancel.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_bugX000.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_extras_dictcursor.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_psycopg2_dbapi20.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_types_basic.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_async.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_lobject.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_cursor.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_with.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/__init__.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_types_extras.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/testutils.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_notify.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_green.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_quote.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_connection.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_transaction.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/dbapi20.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/test_module.py -> build/lib.linux-x86_64-2.7/psycopg2/tests copying tests/dbapi20_tpc.py -> build/lib.linux-x86_64-2.7/psycopg2/tests running build_ext building 'psycopg2._psycopg' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/psycopg x86_64-linux-gnu-gcc -pthread -fno-ssortingct-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wssortingct-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x09010D -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.1/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement In file included from psycopg/psycopgmodule.c:27:0: ./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory #include  ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Cleaning up... Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(comstack(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SgfQCA-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/psycopg2 Traceback (most recent call last): File "/usr/bin/pip", line 9, in  load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 148, in main return command.main(args[1:], options) File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 169, in main text = '\n'.join(complete_log) UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 54: ordinal not in range(128) 

J’ai aussi des erreurs en essayant d’installer gunicorn. J’ai suivi cet exemple ici mais rien. Mon environnement virtuel a été créé à l’aide de l’indicateur --no-site-packages . J’utilise Ubuntu 13.10 et l’environnement grec. Peut-être que c’est ça?

Le paquetage python-dev est requirejs pour la compilation des extensions Python écrites en C ou C ++, comme psycopg2 . Si vous utilisez une dissortingbution basée sur Debian (par exemple Ubuntu), vous pouvez installer python-dev en exécutant

 apt-get install python-dev 

ou

 apt-get install python3-dev 

en fonction de votre version de python.

Après cela, continuez à installer psycopg2 dans votre environnement virtualenv comme d’habitude.

Pour Ubuntu 14.04 , à partir de l’image Docker, python:3.4.3-slim cette combinaison a fonctionné pour moi:

 sudo apt-get update sudo apt-get install -y build-essential sudo apt-get install -y python3.4-dev sudo apt-get install -y libpq-dev pip3 install psycopg2 

Notez le package build-essential . C’était crucial dans mon cas.

Dans mon cas (Ubuntu 12.04 avec python 2.7 et python 3.4 installé)

 sudo apt-get install python3-dev 

n’était pas suffisant. Qu’est-ce que le truc était

 sudo apt-get install python3.4-dev 

Tout d’abord installer python-dev

 sudo apt-get install python-dev 

Et pour une utilisation appropriée, essayez ceci:

Cela est dû au fait que l’encodage de votre terminal n’est pas défini sur UTF-8. Voici mon terminal:

 $ echo $LANG es_UY.UTF-8 $ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89' >>> s1 = s.decode('utf-8') >>> print s1 (。・ω・。)ノ>>> 

Si je ne saisis pas, j’ai la même erreur:

 $ unset LANG $ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89' >>> s1 = s.decode('utf-8') >>> print s1 Traceback (most recent call last): File "", line 1, in  UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128) >>>