postgresql - 尝试使用 python 2.7 在 macosx 10.14.6 上安装 psycopg2
问题描述
我做了 wget bootstrap.pypa.io/ez_setup.py --no-check-certificate sudo python ez_setup.py sudo -H pip install psycopg2 并得到以下错误。
sudo -H pip install psycopg2
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting psycopg2
Using cached psycopg2-2.8.5.tar.gz (380 kB)
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-cnW8Dg/psycopg2/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-cnW8Dg/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/tmp/pip-wheel-rthf3D
cwd: /private/tmp/pip-install-cnW8Dg/psycopg2/
Complete output (279 lines):
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls'
warnings.warn(msg)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.14-intel-2.7
creating build/lib.macosx-10.14-intel-2.7/psycopg2
copying lib/_json.py -> build/lib.macosx-10.14-intel-2.7/psycopg2
copying lib/extras.py -> build/lib.macosx-10.14-intel-2.7/psycopg2
我该如何解决?
解决方案
我试过了 :
- brew reinstall openssl
- pip install psycopg2-binary instead of pip install psycopg2.
它有效。
python
Python 2.7.16 (default, Dec 3 2019, 07:02:07)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> conn = psycopg2.connect(host="localhost",database="postgres", user="appadmin", password="pass1")
>>> cur = conn.cursor()
>>> print('PostgreSQL database version:')
PostgreSQL database version:
>>> cur.execute('SELECT version()')
>>> db_version = cur.fetchone()
>>> print(db_version)
('PostgreSQL 10.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit',)
>>> cur.close()
推荐阅读
- json - 如何在 Perl 中遍历 JSON 对象?
- react-native - Mapbox React Native - 使用表达式格式化 textField 样式属性
- javascript - 以编程方式从 InlineKeyboardMarkup 获取隐藏消息
- javascript - 为什么 php://input 在 JS fetch post 请求上返回 null?
- android - (Unity) Firebase 不适用于 Android 构建
- html - 用于提供多种图像格式和尺寸的图片元素始终以后备结束
- linkedin - 从linkedin API获取公司帖子
- wordpress - Facebook Woocommerce 插件未在 facebook 的产品集中显示产品
- python - 传递 REST API 身份验证令牌在 PostMan 但不是 Python 请求中工作
- rust - 使用 struct 声明内联声明 Enum