无法安装 psycopg2 Ubuntu [英] Cannot install psycopg2 Ubuntu
问题描述
试图为 django 项目准备一个服务器,但我在设置 postgres 时遇到了一些问题.
我正在遵循本指南:https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html
我在第 5 步:
<块引用>- 现在,我们需要配置 postgreSQL,以便它可以与我们的 Django 应用程序进行通信.为此,安装 psycopg2 数据库适配器.但是这个适配器有一些包依赖,所以首先安装它们.
运行:
(django_env) $ sudo apt-get install libpq-dev python3-dev
然后...
(django_env) $ pip install psycopg2
我这样做了,在说明中的这一点,我收到了编译失败"错误.
我尝试了这个堆栈交换问题中建议的解决方案:与 Django 一起使用的 virtualenv python3 中的 psycopg2 问题一>还有这个:无法在 virtualenv 上安装 psycopg2
我非常喜欢 linux 和 django noob,所以如果这是一个重复的问题,请原谅我并发表评论,解释为什么你在这样做时将其标记为重复.
感谢您的时间!
这是导致它的输出和安装命令:
(django_env1) 用户:/home/projects/sample_project$ sudo pip install psycopg2下载/解压psycopg2下载 psycopg2-2.7.3.2.tar.gz (425kB): 425kB 下载为包 psycopg2 运行 setup.py(路径:/tmp/pip_build_root/psycopg2/setup.py)egg_info安装收集的软件包:psycopg2为 psycopg2 运行 setup.py install构建psycopg2._psycopg"扩展x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt declo6q3)"-DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I.-I/usr/include/postgresql -I/usr/include/postgresql/9.3/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement在 psycopg/psycopgmodule.c:27:0 包含的文件中:./psycopg/psycopg.h:34:20: 致命错误: Python.h: 没有那个文件或目录#include ^编译终止.错误:命令x86_64-linux-gnu-gcc"失败,退出状态为 1命令的完整输出/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record/tmp/pip-_0zc1L-record/install-record.txt --single-版本外部管理--编译:运行安装运行构建运行 build_py创建构建创建 build/lib.linux-x86_64-2.7创建 build/lib.linux-x86_64-2.7/psycopg2复制 lib/_ipaddress.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/tz.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/_json.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/__init__.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/errorcodes.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/psycopg1.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/_range.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/extensions.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/sql.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/pool.py ->构建/lib.linux-x86_64-2.7/psycopg2复制 lib/extras.py ->构建/lib.linux-x86_64-2.7/psycopg2创建 build/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_bug_gc.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_psycopg2_dbapi20.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_types_extras.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_async_keyword.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_sql.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_ipaddress.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/dbapi20.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_fast_executemany.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/__init__.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_copy.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_with.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_connection.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_module.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_replication.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_extras_dictcursor.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_dates.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_bugX000.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/testconfig.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_errcodes.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_transaction.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_async.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/testutils.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_cursor.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_quote.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/dbapi20_tpc.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_notify.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_lobject.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_cancel.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_green.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests复制测试/test_types_basic.py ->构建/lib.linux-x86_64-2.7/psycopg2/tests运行 build_ext构建psycopg2._psycopg"扩展创建 build/temp.linux-x86_64-2.7创建 build/temp.linux-x86_64-2.7/psycopgx86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt declo6q3)"-DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I.-I/usr/include/postgresql -I/usr/include/postgresql/9.3/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement在 psycopg/psycopgmodule.c:27:0 包含的文件中:./psycopg/psycopg.h:34:20: 致命错误: Python.h: 没有那个文件或目录#include ^编译终止.错误:命令x86_64-linux-gnu-gcc"失败,退出状态为 1---------------------------打扫干净...命令/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record/tmp/pip-_0zc1L-record/install-record.txt --single-version-externally-managed --compile 失败,错误代码 1 在/tmp/pip_build_root/psycopg2
您已经为 Python 3 安装了 python-dev 库.您的 psycopg2 安装使用的是 python 2.7
确保你已经安装了 python3-pip
sudo apt-get install python3-pip
那么:
pip3 安装 psycopg2
如果仍然失败,请尝试为 postgresql 安装开发头文件:
sudo apt install python3-dev libpq-devpip3 安装 psycopg2
如果在 Python 2 上
sudo apt updatesudo apt-get 安装 postgresql postgresql-contrib须藤 apt-get 安装 libpq-dev须藤 apt-get 安装 python-dev须藤 apt-get 安装 python-pippip2 安装 psycopg2-binary
如果在 Ubuntu 20.04 上
sudo apt-get install build-essential
然后为 Python 2 或 3 运行其他步骤.
Trying to get a server ready for a django project and I'm running into some issues with setup for postgres.
I'm following this guide: https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html
And I'm at step 5:
- Now, we need to configure postgreSQL so that it can communicate with our Django application. For this, install psycopg2 database adapter. But this adapter have some package dependencies, so first install them.
run:
(django_env) $ sudo apt-get install libpq-dev python3-dev
then...
(django_env) $ pip install psycopg2
I do that, and this point in the instructions, I get a "compilation failed" error.
I tried the solutions suggested in this stack exchange question: Trouble with psycopg2 in virtualenv python3 for use with Django and this one: Cannot install psycopg2 on virtualenv
I am very much a linux and django noob, so if this is a duplicate issue, please have mercy on me and leave a comment explaining why you are marking it as a duplicate as you do so.
Thanks for your time!
Here's the output and install command that caused it:
(django_env1) user:/home/projects/sample_project$ sudo pip install psycopg2
Downloading/unpacking psycopg2
Downloading psycopg2-2.7.3.2.tar.gz (425kB): 425kB downloaded
Running setup.py (path:/tmp/pip_build_root/psycopg2/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-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.3/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:34:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-_0zc1L-record/install-record.txt --single-version-externally-managed --compile:
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/_ipaddress.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/psycopg1.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/sql.py -> build/lib.linux-x86_64-2.7/psycopg2
copying lib/pool.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/test_bug_gc.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_extras.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
copying tests/test_async_keyword.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
copying tests/test_sql.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
copying tests/test_ipaddress.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_fast_executemany.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_copy.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/test_connection.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/test_replication.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_dates.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/testconfig.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
copying tests/test_errcodes.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/test_async.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_cursor.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/dbapi20_tpc.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_lobject.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_green.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
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-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.2 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=90320 -DHAVE_LO64=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.3/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:34:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-_0zc1L-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/psycopg2
You've installed the python-dev libraries for Python 3. Your psycopg2 install is using python 2.7
Make sure you've installed python3-pip
sudo apt-get install python3-pip
Then:
pip3 install psycopg2
If that still fails, try installing the development headers for postgresql:
sudo apt install python3-dev libpq-dev
pip3 install psycopg2
If on Python 2
sudo apt update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpq-dev
sudo apt-get install python-dev
sudo apt-get install python-pip
pip2 install psycopg2-binary
If on Ubuntu 20.04
sudo apt-get install build-essential
Then run the other steps for either Python 2 or 3.
这篇关于无法安装 psycopg2 Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!