我无法在Mac上使用Python3安装Psycopg2。我已经安装了Python3和pip3

时间:2019-05-23 12:39:35

标签: python python-3.x psycopg2

我尝试键入以下命令: pip3 install --user psycopg2 psycopg2-binary

重击答案: 错误:正在运行安装

It appears you are missing some prerequisite to build the package from source.

You may install a binary package by installing 'psycopg2-binary' from PyPI.
If you want to install psycopg2 from source, please install the packages
required for the build and try again.

For further information please check the 'doc/src/install.rst' file (also at
<http://initd.org/psycopg/docs/install.html>).

error: command 'gcc' failed with exit status 1
----------------------------------------

错误:命令“ /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -u -c'导入设置工具,标记化; 文件 ='”'“'/ private / var / folders / qf / kmd2_y0j2p9_10zkd5ctvm880000gn / T / pip-install-i0kg4ysj / psycopg2 / setup.py'“'”'; f = getattr(tokenize,'“'”''open'“'”,打开)( file ); code = f.read()。replace('“”“'\ r \ n'”'“','”'“'\ n'”'“')); f.close (); exec(compile(code, file ,'“'”'exec'“'”')))'安装--record / private / var / folders / qf / kmd2_y0j2p9_10zkd5ctvm880000gn / T / pip -record-lkzzuu55 / install-record.txt-“单一版本-外部管理-编译”失败,错误代码为/ private / var / folders / qf / kmd2_y0j2p9_10zkd5ctvm880000gn / T / pip-install-i0kg4ysj / psycopg2 /

2 个答案:

答案 0 :(得分:0)

您无法安装psycopg2,因为设备中的gcc编译器已经过时且无法安装和运行它,或者它不存在。

如果您仅运行pip install psycopg2-binary,则它将在您的开发和测试环境中运行,但是不建议在生产环境中使用。

要安装psycopg2,请通过运行以下命令确保已在设备中安装了gcc-

gcc --version gcc where

如果尚未安装,请参考此处的指南进行安装-

Installing GCC in Mac

我希望这会有所帮助。 :)

答案 1 :(得分:-1)

在成功安装python和pip之后,此命令应该可以运行: pip安装psycopg2