【问题标题】:Installing psycopg2 using Flask/Postgres使用 Flask/Postgres 安装 psycopg2
【发布时间】:2014-05-09 15:58:06
【问题描述】:

我整晚都在寻找解决方案,但是在尝试在 Flask 应用程序的 virtualenv 中安装 psycopg2 时,我似乎遇到了一个不常见的错误。我运行这个命令:

点安装 http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz

这是错误:

创建 build/temp.macosx-10.9-intel-2.7/psycopg

cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090104 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -一世。 -I/Applications/Postgres.app/Contents/MacOS/include -I/Applications/Postgres.app/Contents/MacOS/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-intel-2.7/psycopg/psycopgmodule.o

clang:错误:未知参数:'-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang:注意:这将是一个硬错误(不能降级为 警告)将来

错误:命令“cc”失败,退出状态为 1

---------------------------------------- 命令 /Users/jasdeep1/Dropbox /workspace/Printbase/venv/bin/python -c "导入 setuptools;file='/var/folders/9q/bg9_hgr16s7gt7gdbg8x79wr0000gn/T/pip-TbS4xF-build/setup.py';exec(compile(open(file).读取().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/9q/bg9_hgr16s7gt7gdbg8x79wr0000gn/T/pip-Yavgs4-record/install-record.txt --single-version-externally-managed --install-headers /Users/jasdeep1/Dropbox/workspace/Printbase/venv/include/site/python2.7 失败,错误代码为 1 /var/folders/9q/bg9_hgr16s7gt7gdbg8x79wr0000gn/T/pip-TbS4xF-build 在 /Users/jasdeep1/.pip/pip.log 中存储完整的日志

不完全确定如何解决这个问题。我见过的任何答案似乎都没有解决这个问题。任何朝着正确方向迈出的帮助表示赞赏。

很高兴分享更多调试输出,但不确定有多少细节是太多细节。

【问题讨论】:

标签: python postgresql flask psycopg2


【解决方案1】:

您可能想直接从 pip 安装 psycopg2 —— 不知道为什么要手动安装 tarball(尽管假设您已经安装了 libpq-devbuild-essential install ,它应该可以工作)。

$ pip install -U psycopg2

【讨论】:

    【解决方案2】:

    安装:打开终端(编辑器或本地)

    $ brew install postgresql
    $ brew services start postgresql
    

    然后转到 sql 提示创建数据库(不要离开终端):

    $ psql postgres
    

    CREATE DATABASE .. CREATE USER GRANT ...

    和连接示例:

    def con_db():
        conn = None
        cursor = None
    
        try:
            conn = psycopg2.connect("host= dbname= user= password=")
    
            cursor = conn.cursor()
            sql_query = """select .."""
            cursor.execute(sql_query)
    
            # conn.commit()
            result = cursor.fetchall()  # fetchone()
    
        except Exception as e:
            print(e)
        finally:
            cursor.close()
            conn.close()
    

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      • 2020-02-17
      • 2020-05-31
      • 2018-09-23
      • 2015-08-14
      • 2013-08-30
      相关资源
      最近更新 更多