Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法安装psycopg2(pip安装psycopg2)_Python_Postgresql_Pip_Psycopg2 - Fatal编程技术网

Python 无法安装psycopg2(pip安装psycopg2)

Python 无法安装psycopg2(pip安装psycopg2),python,postgresql,pip,psycopg2,Python,Postgresql,Pip,Psycopg2,我使用的是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

我使用的是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

如果使用的是较旧的Python,而没有最安全的TLS实现,则需要对其进行升级。否则,您将无法从PyPI“pip安装”软件包

1) 要检查Python解释器的TLS版本,请安装“requests”包并运行命令。例如,对于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'])"
或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'])"
如果您看到“TLS1.2”,您的口译员的TLS是最新的。如果看到“TLS 1.0”或类似“tlsv1警报协议版本”的错误,则必须升级

2) Python的TLS实现在macOS上落后的原因是Python继续使用OpenSSL,苹果已经停止在macOS上更新OpenSSL。在未来的一年中,Python打包管理局团队将研究将pip移植到苹果自己的“SecureTransport”库中,作为OpenSSL的替代方案,这将允许旧的Python解释器仅使用带有pip的现代TLS。Stufft写道:“这是一项非常重要的工作,我不确定它是否能完成。”

从长远来看,如果Python解释器在macOS和Windows等平台上不使用OpenSSL,而这些平台上的操作系统不附带OpenSSL,那么Python解释器本身将很容易跟上TLS版本。Cory Benfield和Christian Heimes建议重新设计标准库的TLS接口,使OpenSSL与平台本机TLS实现的交换更加容易。

尝试以下方法:

pip install psycopg2-binary

我遇到了这个问题,在这里成功地提问和回答:

[保存您的点击]

我已经安装了蟒蛇2。安装程序将我的路径更新为包含/anaconda/bin

然后使用导航器安装了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
>>> 

*我用进程监视器进行了跟踪。 D:\Anaconda3\DLLs\u ssl.pyd在错误/当前位置搜索OpenSSL DLL! 由于没有找到它们,搜索转到C:\Windows\System32,在那里我们有相同的DLL,由其他应用程序安装,但版本不同

Anaconda3交付的DLL位于以下位置: D:\Anaconda3\Library\bin

分辨率

我的解决方法: 我复制了以下文件

libcrypto-1_1-x64* libssl-1_1-x64*
D:\Anaconda3\Library\binD:\Anaconda3\DLLs.

第一个
pip卸载psycopg2 psycopg2二进制文件的可能副本
然后
pip安装psycopg2
。这样就不会搞砸了