配置VSCode以使用pip

时间:2019-03-20 14:08:16

标签: python python-3.x visual-studio-code ssl-certificate

我正在尝试设置VSCode以允许我运行Python程序。

我在Windows 10上。

当前,如果我创建简单的程序(如

),它可以正常工作
# This all works fine
print("Hello World")
arr = [1,2,3]
print(arr)

但是,当我使用numpy之类的 any 外部库时,出现以下错误:

  

回溯(最近通话最近):     文件“ c:/Users/jerry/Desktop/hello.py”,第3行,在       将numpy导入为np   ImportError:没有名为“ numpy”的模块

因此,我在VSCode终端窗口中发出以下命令:pip install numpy

哪个让我以下:

PS C:\Users\jerry> pip install numpy
Collecting numpy
Exception:
Traceback (most recent call last):
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 539, in urlopen
    self._prepare_proxy(conn)
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 727, in _prepare_proxy
    conn.connect()
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\packages\urllib3\connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py", line 279, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "c:\python35-32\lib\ssl.py", line 376, in wrap_socket
    _context=self)
  File "c:\python35-32\lib\ssl.py", line 747, in __init__
    self.do_handshake()
  File "c:\python35-32\lib\ssl.py", line 983, in do_handshake
    self._sslobj.do_handshake()
  File "c:\python35-32\lib\ssl.py", line 628, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\adapters.py", line 370, in send
    timeout=timeout
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 574, in urlopen
    raise SSLError(e)
pip._vendor.requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python35-32\lib\site-packages\pip\basecommand.py", line 211, in main
    status = self.run(options, args)
  File "c:\python35-32\lib\site-packages\pip\commands\install.py", line 294, in run
    requirement_set.prepare_files(finder)
  File "c:\python35-32\lib\site-packages\pip\req\req_set.py", line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "c:\python35-32\lib\site-packages\pip\req\req_set.py", line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "c:\python35-32\lib\site-packages\pip\req\req_set.py", line 491, in _prepare_file
    session=self.session)
  File "c:\python35-32\lib\site-packages\pip\download.py", line 825, in unpack_url
    session,
  File "c:\python35-32\lib\site-packages\pip\download.py", line 673, in unpack_http_url
    from_path, content_type = _download_http_url(link, session, temp_dir)
  File "c:\python35-32\lib\site-packages\pip\download.py", line 857, in _download_http_url
    stream=True,
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
  File "c:\python35-32\lib\site-packages\pip\download.py", line 373, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "c:\python35-32\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "c:\python35-32\lib\site-packages\pip\_vendor\requests\adapters.py", line 431, in send
    raise SSLError(e, request=request)
pip._vendor.requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)
You are using pip version 7.1.2, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

我不确定该怎么办或如何解决此错误。我已经审查了以下资源:

都没有可行的解决方案。任何建议或帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

这是由于代理服务器出现问题,该问题已通过我的防火墙设置修复。 对我来说,问题是需要添加一个特定的证书颁发机构,该证书颁发机构应承载仅Intranet的Python库集合。

该证书颁发机构和证书是专有的,无法发布。