我在 Redhat Enterprise 6 中设置了一个基于 Python 2.7 的 virtualenv(默认情况下附带 2.6.x)。
我安装了 Python 的 SCL 2.7 版本,然后创建了 virtualenv:
$ scl enable python27 bash
$ cd /my/project
$ virtualenv -v --clear --extra-search-dir=/opt/rh/python27/root/usr/bin/ --python=/opt/rh/python27/root/usr/bin/python virtualenv
$ source virtualenv/bin/acticvate
到目前为止,一切都很好。当我尝试在我机构的代理后面运行 pip 时,问题就开始了:
$ pip install Werkzeug --proxy proxy.example.org:3128
Downloading/unpacking Werkzeug
Cleaning up...
Exception:
Traceback (most recent call last):
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/basecommand.py", line 134, in main
status = self.run(options, args)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/commands/install.py", line 236, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/req.py", line 1085, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 201, in find_requirement
page = self._get_page(main_index_url, req)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 554, in _get_page
return HTMLPage.get_page(link, req, cache=self.cache)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 671, in get_page
resp = urlopen(url)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 176, in __call__
response = self.get_opener(scheme=scheme).open(url)
File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 155, in https_open
return self.do_open(self.specialized_conn_class, req)
File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 1183, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 1035, in _send_request
self.endheaders(body)
File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 997, in endheaders
self._send_output(message_body)
File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 850, in _send_output
self.send(msg)
File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 812, in send
self.connect()
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 139, in connect
match_hostname(self.sock.getpeercert(), self.host)
File "/my/project/virtualenv/lib/python2.7/site-packages/pip/backwardcompat/ssl_match_hostname.py", line 61, in match_hostname
% (hostname, ', '.join(map(repr, dnsnames))))
CertificateError: hostname 'proxy.example.org' doesn't match either of 'www.python.org', 'python.org', 'pypi.python.org', 'docs.python.org', 'testpypi.python.org', 'bug>>>s.python.org', 'wiki.python.org', 'hg.python.org', 'mail.python.org', 'packaging.python.org', 'pythonhosted.org', 'www.pythonhosted.org', 'test.pythonhosted.org', 'us.py>>>con.org', 'id.python.org', 'pypi.io'
我在其他问题中看到了这个问题,但这些似乎都不适用于我的情况。
编辑:
例如,我尝试在https://stackoverflow.com/questions/21468550/pip-not-working-behind-firewall中设置环境变量。其他案例正在解决 Windows 问题。
值得一提的是,如果我不在 scl 环境中,这个 virtualenv 将无法工作,例如,如果我调用python
启用 virtualenv 而不是 scl,它会抱怨找不到 libpython2.7.so.1.0。我不知道这是否是 bny 设计,但我希望 Python 2.7 依赖的所有库都在 virtualenv 中进行符号链接或复制。也许我在 virtualenv 安装中做错了什么?