[英]Installing psycopg2 using Flask/Postgres
我整夜都在尋找解決方案,但我似乎在嘗試在 Flask 應用程序的 virtualenv 中安裝 psycopg2 時遇到了一個不常見的錯誤。 我運行這個命令:
pip 安裝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_4dec3t="p 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。 -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 "import setuptools; file ='/var/folders/9q/bg9_hgr16s7gt7gdbg8x79wr0000gn/T/pip-TbS4xF-build/setup.py';exec(compile(open( file ).read() .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 中存儲完整的日志
不完全確定如何解決這個問題。 我見過的沒有答案似乎可以解決這個問題。 任何朝着正確方向邁進的幫助表示贊賞。
很高興分享更多調試輸出,但不確定有多少細節是太多細節。
您可能想直接從pip安裝psycopg2
-不知道為什么要手動安裝tarball(盡管,如果您已經具有libpq-dev
和build-essential
install,它應該可以工作)。
$ pip install -U psycopg2
安裝:打開終端(編輯器或本地)
$ brew install postgresql
$ brew services start postgresql
並轉到 sql promp 創建一個數據庫(不要離開終端):
$ 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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.