postgresql 无法安装 psycopg2 (pip install psycopg2)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49811955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to install psycopg2 (pip install psycopg2)
提问by Rakesh Kumar
I'm using MAC and python version 2.7.14
我使用的是 MAC 和 python 版本 2.7.14
Collecting psycopg2
Could not fetch URL https://pypi.python.org/simple/psycopg2/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
Could not find a version that satisfies the requirement psycopg2 (from versions: )
No matching distribution found for psycopg2
回答by oneor0
Try this:
试试这个:
pip install psycopg2-binary
回答by mdegis
You're using an older Python without the most secure TLS implementation, you need to upgrade it. Otherwise, you will not be able to "pip install" packages from PyPI.
您使用的是没有最安全 TLS 实现的旧 Python,您需要升级它。否则,您将无法从 PyPI 中“pip install”软件包。
1) To check your Python interpreter's TLS version, install the "requests" package and run a command. For example, for Python 2:
1) 要检查 Python 解释器的 TLS 版本,请安装“请求”包并运行命令。例如,对于 Python 2:
python2 -m pip install --upgrade requests
python2 -c "import requests;
print(requests.get('https://www.howsmyssl.com/a/check',verify=False).json()['tls_version'])"
Or Python 3:
或 Python 3:
python3 -m pip install --upgrade requests
python3 -c "import requests;
print(requests.get('https://www.howsmyssl.com/a/check',verify=False).json()['tls_version'])"
If you see "TLS 1.2", your interpreter's TLS is up to date. If you see "TLS 1.0" or an error like "tlsv1 alert protocol version", then you must upgrade.
如果您看到“TLS 1.2”,则您的解释器的 TLS 是最新的。如果您看到“TLS 1.0”或“tlsv1 警报协议版本”之类的错误,则必须升级。
2) The reason Python's TLS implementation is falling behind on macOS is that Python continues to use OpenSSL, which Apple has stopped updating on macOS. In the coming year, the Python Packaging Authority team will investigate porting pip to Apple's own "SecureTransport" library as an alternative to OpenSSL, which would allow old Python interpreters to use modern TLS with pip only. "This is a non-trivial amount of effort," writes Stufft, "I'm not sure it's going to get done."
2)Python 的 TLS 实现在 macOS 上落后的原因是 Python 继续使用 OpenSSL,Apple 已停止在 macOS 上更新。在来年,Python Packaging Authority 团队将研究将 pip 移植到 Apple 自己的“SecureTransport”库,作为 OpenSSL 的替代方案,这将允许旧的 Python 解释器仅使用带有 pip 的现代 TLS。“这是一项不小的努力,”Stufft 写道,“我不确定它是否会完成。”
In the long run, the Python interpreter itself would easily keep up with TLS versions, if it didn't use OpenSSL on platforms like macOS and Windows where OpenSSL is not shipped with the OS. Cory Benfield and Christian Heimes propose to redesign the standard library's TLS interfaces to make it easier to swap OpenSSL with platform-native TLS implementations.
从长远来看,Python 解释器本身很容易跟上 TLS 版本,如果它不在 OS 未附带 OpenSSL 的 macOS 和 Windows 等平台上使用 OpenSSL。Cory Benfield 和 Christian Heimes 提议重新设计标准库的 TLS 接口,以便更容易地将 OpenSSL 与平台原生 TLS 实现交换。
回答by VynlJunkie
I had this issue, asked and answered succesfully here:
我遇到了这个问题,在这里提问并成功回答:
Cannot get psycopg2 to work, but installed correctly. Mac OS
[save you a click]
[省你一次点击]
I have installed anaconda2. The install updated my path to include /anaconda/bin.
我已经安装了anaconda2。安装更新了我的路径以包含 /anaconda/bin。
Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i'm able to import this module.
然后使用导航器安装了 pyscopg2。现在我可以在 shebang 中使用它,我的脚本执行得很好,我可以导入这个模块。
Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
... print "connection made"
...
connection made
>>>