无法安装 psycopg2 Ubuntu

2024-05-09

试图为 django 项目准备好服务器,但我在设置 postgres 时遇到了一些问题。

我正在遵循本指南:https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html

我现在处于第 5 步:

  1. 现在,我们需要配置 postgreSQL,以便它可以与我们的 Django 应用程序进行通信。为此,安装 psycopg2 数据库 适配器。但是这个适配器有一些包依赖性,所以首先 安装它们。

run:

(django_env) $ sudo apt-get install libpq-dev python3-dev

then...

(django_env) $ pip install psycopg2

我这样做了,在说明中的这一点上,我收到“编译失败”错误。

我尝试了此堆栈交换问题中建议的解决方案:virtualenv python3 中的 psycopg2 与 Django 一起使用时出现问题 https://stackoverflow.com/questions/24157533/trouble-with-psycopg2-in-virtualenv-python3-for-use-with-django和这个:无法在 virtualenv 上安装 psycopg2 https://stackoverflow.com/questions/27195490/cannot-install-psycopg2-on-virtualenv

我是一个 Linux 和 django 菜鸟,所以如果这是一个重复的问题,请怜悯我并留下评论解释为什么你这样做时将其标记为重复。

谢谢你的时间!

这是导致它的输出和安装命令:

(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

您已经安装了 Python 3 的 python-dev 库。您的 psycopg2 安装使用的是 python 2.7

如果在 Ubuntu 20.04 或更高版本上

sudo apt-get install build-essential

然后针对 Python 2 或 3 运行其他步骤:

如果你想使用Python 3:

确保你已经安装了 python3-pip

sudo apt-get install python3-pip

Then:

pip3 install psycopg2

如果仍然失败,请尝试安装 postgresql 的开发标头:

sudo apt install python3-dev libpq-dev
pip3 install psycopg2

如果在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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法安装 psycopg2 Ubuntu 的相关文章

随机推荐

  • 如何通过情节提要向导航栏添加后退按钮?

    我现在很困惑 我在网上到处都看到添加自定义后退按钮的教程 但我什至似乎无法启动默认按钮 在我的 MainViewController 中 我有performSegueWithIdentifier 然后在另一端 我希望导航栏在左侧有后退按钮
  • 我应该开发一个单独的 Express 服务器,还是处理 next.js 应用程序中的所有 API 调用?

    我的网站将执行 CRUD 操作 并将与 MongoDB 和 Firebase 存储 身份验证配合使用 开发单独的 Express 服务器而不是将所有内容集成到我的 next js 应用程序中的原因 优势是什么 据我所知 这一切都可以在我的
  • Cloudwatch 仪表板:具有独立时间范围的小部件?

    我希望仪表板中的每个小部件都有自己的时间范围 我找不到办法做到这一点 如果不可能的话 我会发现它令人难以置信 我希望我的仪表板包含以下内容堆积区域小部件 过去一小时内 30 秒周期的请求计数 即 120 个绘图点 过去一天以 1 小时为周期
  • 当应用程序停止使用 Sencha Touch 2.2 和 Phonegap 时,LocalStorage 存储不会保留在 Android 手机上

    这在我的浏览器中工作正常 但是当我在手机上安装该应用程序并使用它时 它看起来很好 直到我强制它停止并重新打开该应用程序 然后我的所有记录都消失了 我正在使用 2 2 和 Phonegap 任何帮助将非常感激 这是我的商店 Ext defin
  • 无法在Python中打开html5lib

    我刚刚使用 Windows 命令提示符安装了适用于 Python 的 html5lib 该软件包安装在这里 File C Python27 lib site packages html5lib 但是 如果我尝试导入 html5lib usr
  • gradle 过滤 src/main/webapp 中文件子集的方法是什么?

    我正在将 Maven 转换为 gradle 希望了解执行以下操作的最佳方式的意见 我目前在 src main webapp 下有多个文件 有些需要以一种方式过滤 有些需要以另一种方式过滤 理论上 在 src main webapp 下 我有
  • 在 Angular 中,如何动态地将某些单词包装在另一个 html 元素中?

    我有这个简单的角度组件 Component selector my component template p someString p export class MyComponent Input someString string som
  • Perl 6:检查元素是否在列表中的最佳方法是什么?

    假设我有一个大数组 stuff and a thing 我想知道是否 thing is in stuff 在 Perl 6 中做到这一点的最佳方法是什么 我所说的 最好 是指 惯用的 可读的 高性能的 不一定按这个顺序 实际上有两个单独的案
  • 重用 Jsoup 连接

    我喜欢 Jsoup 来解析 html 但它们的连接有问题 我需要向同一个网站但不同的查询参数发送请求 比如 id XXX 请求如下 http website id XXX 我不想为每个 id 创建一个新连接 而是为所有 id 请求保留一个连
  • 将 DIV 扩展到父列表项之外

    我有一个有序列表 它实际上是页面上产品的显示 在每个列表项中 li 有一些内容 后面跟着一个div在关闭列表项之前包含更多内容 我需要每个列表项中的 div 扩展 其宽度 超出其父列表项 并实际填充有序列表的宽度 ol 每个 div 还需要
  • iOS 中的 FacebookSDK 不显示关闭按钮且无法关闭

    您好 我已经为 iOS 6 应用程序集成了 Facebook SDK Facebook 身份验证和共享工作完美 但没有提供关闭 FB 对话框的规定 当FB对话框打开时 只有在身份验证成功后才会关闭 没有关闭或导航回来的规定 我如何制作关闭按
  • 操作按钮未出现在通知 iOS 10 中

    我在我的应用程序中使用本地推送通知 在 iOS 10 中为通知添加操作按钮时 它不会出现在通知下方 通知正在显示 但通知底部缺少操作按钮 下面给出了 appdelegate 代码 import UIKit import CoreData i
  • Scipy 最小化 fmin - 语法问题

    我有一个函数 它接受多个参数 一个数组和两个浮点数 并返回一个标量 浮点数 现在我想通过改变两个参数来最小化这个函数 两个浮点数 该数组在函数内部 解包 然后使用其内容 数组和浮点数 如何使用 SciPy 的 fmin 函数来完成此操作 我
  • Python 2 中的 Python 3 舍入行为

    在 Python 2 x 中 内置round http docs python org 2 library functions html round有以下行为 如果两个倍数同样接近 则进行四舍五入远离0 例如 round 0 5 是 1 0
  • Android,无法从谷歌API获取天气

    以下代码之前运行良好 class RetreiveWeatherTask extends AsyncTask
  • 创建用于插入、修改和删除的数据库触发器的正确​​语法是什么

    我有一个看起来像是 SQL Server 中数据库触发器的基本场景 但我遇到了一个问题 我有桌子Users 身份证 姓名 电话等 我有桌子用户历史记录 id user id 操作 字段 时间戳 我想要一个数据库触发器 可以随时插入 更新或删
  • 标签转换问题

    我是 html css 新手 当用户在输入框中输入无效输入时出现错误 然后特定输入字段的标签会下降 但是当用户输入时 输入正确则工作正常
  • 将单引号括起来的数组转换为数组

    深度嵌套在 JSON 对象中我有属性value actions name InviteUser type button value Brian Timoney email protected cdn cgi l email protecti
  • 如何以编程方式从 mipmap 文件夹加载图像? [复制]

    这个问题在这里已经有答案了 如何从 加载图像mipmap以编程方式保存文件夹 与可绘制对象一样 img setImageResource imageId 我使用的是Android Studio 1 2 1 In 安卓工作室我们有mipmap
  • 无法安装 psycopg2 Ubuntu

    试图为 django 项目准备好服务器 但我在设置 postgres 时遇到了一些问题 我正在遵循本指南 https jee appy blogspot com 2017 01 deply django with nginx html ht