Python 无法安装psycopg2 Ubuntu

Python 无法安装psycopg2 Ubuntu,python,django,postgresql,ubuntu,psycopg2,Python,Django,Postgresql,Ubuntu,Psycopg2,试图为django项目准备服务器时,我遇到了一些关于postgres设置的问题 我遵循以下指南: 我在第五步: 现在,我们需要配置postgreSQL,以便它能够与Django应用程序通信。为此,请安装psycopg2数据库 适配器。但是这个适配器有一些包依赖关系,所以首先 安装它们 运行: (django_env)$sudo apt get安装libpq dev python3 dev 然后 (django_env)$pip安装psycopg2 我这样做了,在指令的这一点上,我得到了一个“编

试图为django项目准备服务器时,我遇到了一些关于postgres设置的问题

我遵循以下指南:

我在第五步:

  • 现在,我们需要配置postgreSQL,以便它能够与Django应用程序通信。为此,请安装psycopg2数据库 适配器。但是这个适配器有一些包依赖关系,所以首先 安装它们
  • 运行:

    (django_env)$sudo apt get安装libpq dev python3 dev

    然后

    (django_env)$pip安装psycopg2

    我这样做了,在指令的这一点上,我得到了一个“编译失败”的错误

    我尝试了此堆栈交换问题中建议的解决方案: 还有这个:

    我非常喜欢linux和django noob,所以如果这是一个重复的问题,请原谅我,并留下一条评论,解释为什么您在这样做时将其标记为重复

    谢谢你的时间

    以下是导致该问题的输出和安装命令:

    (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
    
    (django_env1)用户:/home/projects/sample_project$sudo pip install psycopg2
    下载/解包psycopg2
    下载psycopg2-2.7.3.2.tar.gz(425kB):下载425kB
    运行setup.py(路径:/tmp/pip\u build\u root/psycopg2/setup.py)包psycopg2的egg\u信息
    安装收集的软件包:psycopg2
    正在为psycopg2运行setup.py安装
    构建“psycopg2.\u psycopg”扩展
    x86_64-linux-gnu-gcc-pthread-fno严格别名-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型-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-wdecaration after语句
    在psycopg/psycopgmodule.c中包含的文件中:27:0:
    ./psycopg/psycopg.h:34:20:致命错误:Python.h:没有这样的文件或目录
    #包括
    ^
    编译终止。
    错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为1
    从命令/usr/bin/python-c“import setuptools,tokenize;_文件_uu=”/tmp/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize,'open',open)(__u文件_u=”.read().replace('\r\n','n'),__u文件‘,'exec')))安装--record/tmp/pip-record/install-record.txt外部管理的单一版本--编译:
    正在运行的安装
    运行构建
    运行build\u py
    创建构建
    创建build/lib.linux-x86_64-2.7
    创建build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/_ipaddress.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/tz.py->build/lib.linux-x86_64-2.7/psycopg2
    复制lib/_json.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/uuu init_uuuu.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/errorcodes.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/psycopg1.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/_range.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/extensions.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/sql.py->build/lib.linux-x86_64-2.7/psycopg2
    正在复制lib/pool.py->build/lib.linux-x86_64-2.7/psycopg2
    复制lib/extras.py->build/lib.linux-x86_64-2.7/psycopg2
    创建build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u bug\u gc.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test\u psycopg2\u dbapi20.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/测试类型\u extras.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test\u async\u keyword.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test\u sql.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test_ipaddress.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/dbapi20.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u fast\u executemany.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    正在复制测试/_init__.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u copy.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制tests/test_with.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_connection.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_module.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u replication.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test_extras_dictcursor.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_dates.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_bugX000.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    正在复制tests/testconfig.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_errcodes.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_transaction.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test_async.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制tests/testutils.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u cursor.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test_quote.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/dbapi20_tpc.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u notify.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test_lobject.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/test\u cancel.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    复制测试/test_green.py->build/lib.linux-x86_64-2.7/psycopg2/tests
    复制测试/测试类型\u basic.py->build/lib.linux-x86\u 64-2.7/psycopg2/tests
    运行build_ext
    构建“psycopg2.\u psycopg”扩展
    创建build/temp.linux-x86_64-2.7
    创建build/temp.linux-x86_64-2.7/psycopg
    x86_64-linux-gnu-gcc-pthread-fno严格别名-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型-fPIC-DPSYCOPG_默认值\u PYDATETIME=1-DPSYCOPG_VERSION=“2.7.3.2(dt dec pq3 ext lo64)”-DPG_VERSION\u NUM=90320-DHAVE\u lo64=1-I/u
    
    sudo apt-get install python3-pip
    
    pip3 install psycopg2
    
    sudo apt install python3-dev libpq-dev
    pip3 install psycopg2
    
    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
    
    sudo apt-get install build-essential
    
    sudo apt update
    sudo apt-get install postgresql postgresql-contrib
    sudo apt-get install libpq-dev # this is required as psycopg2 uses pg_config
    sudo apt-get install python-dev
    sudo apt-get install python-pip
    
    pip2 install psycopg2-binary
    
    sudo apt-get install build-essential
    
    sudo apt-get install python3-dev
    sudo apt-get install python3-pip
    pip install psycopg2
    
    sudo apt install python3-dev libpq-dev
    pip3 install psycopg2