python - 如何在 Mac OS Sierra 上使用 Virtualenv 安装 PyGreSQL

标签 python postgresql pip virtualenv pygresql

我正在配置一个 virtualenv 以使用在 python 上使用 flask microframework 和 PostgreSQL 数据库开发的遗留网络服务应用程序,这个应用程序使用 PyGreSQL 5.0.3 作为连接数据库的依赖项。

我已经安装了 PostgreSQL 9.6.1,我安装它使用:

brew 安装 postgresql

我已经安装并使用 Python 2.7

当我运行

pip install -r requirements.txt

我收到此错误消息:

Running setup.py install for PyGreSQL ... error
Complete output from command /Users/user/Development/Projects/flask/ws/myenv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/t1/x7lrbmyd3lq0k8ngknwg1zx00000gn/T/pip-build-KjQgiU/PyGreSQL/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/t1/x7lrbmyd3lq0k8ngknwg1zx00000gn/T/pip-3lBp1N-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/user/Development/Projects/flask/ws/myenv/include/site/python2.7/PyGreSQL:
running install
running build
running build_py
creating build
creating build/lib.macosx-10.12-intel-2.7
copying pg.py -> build/lib.macosx-10.12-intel-2.7
copying pgdb.py -> build/lib.macosx-10.12-intel-2.7
running build_ext
building '_pg' extension
creating build/temp.macosx-10.12-intel-2.7
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -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 -DPYGRESQL_VERSION=5.0.3 -DDIRECT_ACCESS -DLARGE_OBJECTS -DDEFAULT_VARS -DESCAPING_FUNCS -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/Cellar/postgresql/9.6.1/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pgmodule.c -o build/temp.macosx-10.12-intel-2.7/pgmodule.o -O2 -funsigned-char -Wall -Werror
pgmodule.c:4143:9: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                num = PyInt_AsLong(param);
                    ~ ^~~~~~~~~~~~~~~~~~~
pgmodule.c:4448:12: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                pgport = PyInt_AsLong(pg_default_port);
                       ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
error: command 'cc' failed with exit status 1

----------------------------------------

如您所见,此错误源自编译和构建包,但我安装了 postgresql 库,我认为这是其他情况下的常见问题。另一方面,我已经安装了 mac 的命令行工具,我将编译器从 cc 更改为 gcc 并且我遇到了同样的错误

知道怎么解决吗,谢谢

最佳答案

我无法正常安装此软件包的任何版本。可能是包的问题。

解决方法:如果您关闭错误警告,它应该可以正常编译。

export CFLAGS="-Wno-error"
pip install PyGreSQL

关于python - 如何在 Mac OS Sierra 上使用 Virtualenv 安装 PyGreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173297/

相关文章:

python - 嵌入式 pdf 文件未显示在 Django 中

python - 图像配准 B 样条 opencv

sql - 如何使 PostgresQL 优化器在绑定(bind)参数后构建执行计划?

mysql - 如何使用 C# 获取 Oracle、SQL Server、postgres、mysql 或任何其他数据库的数据库实例和架构详细信息?

pip - 使用 tox 安装 extra_requires

python - lxml 3.1.2 和 lxml2 都在 ubuntu 上

python - 为什么 p[ :] designed to work differently in these two situations?

python - 从 Numpy 向量数组中删除重复项(在给定的公差范围内)

sql - 在 postgres 中显示所有非空表

pip - 使用pip或pip3安装virtualenv?