无法安装psycopg2(pip install psycopg2)

时间:2018-04-13 07:54:15

标签: python postgresql pip

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

7 个答案:

答案 0 :(得分:4)

您使用较旧的Python而没有最安全的TLS实现,您需要升级它。否则,您将无法从PyPI“pip install”包。

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'])"

如果您看到“TLS 1.2”,则您的口译员的TLS是最新的。如果您看到“TLS 1.0”或“tlsv1 alert protocol version”之类的错误,则必须升级。

2)Python的TLS实现落后于macOS的原因是Python继续使用OpenSSL,Apple已经停止在macOS上更新。在接下来的一年中,Python Packaging Authority团队将调查将pip移植到Apple自己的“SecureTransport”库,作为OpenSSL的替代方案,这将允许旧的Python解释器仅使用带有pip的现代TLS。 “这是一项非常重要的努力,”Stufft写道,“我不确定它会完成。”

从长远来看,Python解释器本身很容易跟上TLS版本,如果它没有在Mac OS和Windows等平台上使用OpenSSL,而OpenSSL不随OS一起提供。 Cory Benfield和Christian Heimes建议重新设计标准库的TLS接口,以便更容易地将OpenSSL与平台本地TLS实现交换。

答案 1 :(得分:4)

试试这个:

pip install psycopg2-binary

答案 2 :(得分:3)

同样的问题,忘记安装psql: https://wiki.postgresql.org/wiki/Homebrew

所以我跑了:

brew install postgresql
brew services start postgresql

答案 3 :(得分:0)

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

Cannot get psycopg2 to work, but installed correctly. Mac OS

[保存点击]

我安装了anaconda2。安装更新了我的路径include / anaconda / bin。

然后使用导航器我安装了pyscopg2。现在我可以在shebang中使用它,我的脚本执行正常,我可以导入这个模块。

var app = new Vue({
  el: '#app',
  mounted:function(){
        jQuery("#jsGrid").jsGrid({
        width: "100%",
        height: "400px",
        inserting: true,
        editing: true,
        sorting: true,
        paging: true,
        data: this.clients,
        fields: [
            { name: "Name", type: "text", width: 150, validate: "required" },
            { name: "Age", type: "number", width: 50 },
            { name: "Address", type: "text", width: 200 },
            { name: "Country", type: "select", items: this.countries, valueField: "Id", textField: "Name" },
            { name: "Married", type: "checkbox", title: "Is Married", sorting: false },
            { type: "control" }
        ]
    });
  },
  data: {
    message: 'Hello Vue App!',
    clients : [
        { "Name": "Otto Clay", "Age": 25, "Country": 1, "Address": "Ap #897-1459 Quam Avenue", "Married": false },
        { "Name": "Connor Johnston", "Age": 45, "Country": 2, "Address": "Ap #370-4647 Dis Av.", "Married": true },
        { "Name": "Lacey Hess", "Age": 29, "Country": 3, "Address": "Ap #365-8835 Integer St.", "Married": false },
        { "Name": "Timothy Henson", "Age": 56, "Country": 1, "Address": "911-5143 Luctus Ave", "Married": true },
        { "Name": "Ramona Benton", "Age": 32, "Country": 3, "Address": "Ap #614-689 Vehicula Street", "Married": false }
    ],
    countries :[
        { Name: "", Id: 0 },
        { Name: "United States", Id: 1 },
        { Name: "Canada", Id: 2 },
        { Name: "United Kingdom", Id: 3 }
    ],
    
  }
});

答案 4 :(得分:0)

我收到如下错误消息。

AttributeError: 'module' object has no attribute 'X509_up_ref' Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)': /simple/cryptography/ From cffi callback <function _verify_callback at 0x110038848>: Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 313, in wrapper _lib.X509_up_ref(x509) AttributeError: 'module' object has no attribute 'X509_up_ref' Could not fetch URL https://pypi.org/simple/cryptography/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/cryptography/ (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)) - skipping Could not find a version that satisfies the requirement cryptography>=2.1.4 (from pyopenssl) (from versions: ) No matching distribution found for cryptography>=2.1.4 (from pyopenssl) From cffi callback <function _verify_callback at 0x11007a578>: Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 313, in wrapper _lib.X509_up_ref(x509) AttributeError: 'module' object has no attribute 'X509_up_ref' Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)) - skipping

我尝试卸载pyopenssl并重新安装了它。然后,成功安装了psycopg2。

pip uninstall pyopenssl
pip install pyopenssl
pip install psycopg2

答案 5 :(得分:0)

*我使用Process Monitor进行了跟踪。 D:\ Anaconda3 \ DLLs_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 \ bin D:\ Anaconda3 \ DLLs。

答案 6 :(得分:0)

我在 docker 设置中遇到了类似的问题。我使用了下面的包而不是 psycopg2

pip install psycopg2-binary