pycharm工程中的pip用不了怎么办?

Posted 昊虹算法

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pycharm工程中的pip用不了怎么办?相关的知识,希望对你有一定的参考价值。

在使用pycharm工程中的pip安装sympy时报以下错:

ERROR: Exception:
Traceback (most recent call last):
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py", line 438, in _error_catcher
    yield
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\cachecontrol\\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\http\\client.py", line 449, in read
    n = self.readinto(b)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\http\\client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ssl.py", line 1012, in recv_into
    return self.read(nbytes, buffer)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ssl.py", line 874, in read
    return self._sslobj.read(len, buffer)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\cli\\base_command.py", line 180, in _main
    status = self.run(options, args)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\cli\\req_command.py", line 204, in wrapper
    return func(self, options, args)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\commands\\install.py", line 319, in run
    reqs, check_supported_wheels=not options.target_dir
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\resolver.py", line 128, in resolve
    requirements, max_rounds=try_to_avoid_resolution_too_deep
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 473, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 341, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 172, in _merge_into_criterion
    if not criterion.candidates:
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\structs.py", line 139, in __bool__
    return bool(self._sequence)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 143, in __bool__
    return any(self)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 129, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 33, in _iter_built
    candidate = func()
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\factory.py", line 205, in _make_candidate_from_link
    version=version,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\candidates.py", line 312, in __init__
    version=version,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\candidates.py", line 151, in __init__
    self.dist = self._prepare()
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\candidates.py", line 234, in _prepare
    dist = self._prepare_distribution()
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\candidates.py", line 318, in _prepare_distribution
    self._ireq, parallel_builds=True
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\operations\\prepare.py", line 508, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\operations\\prepare.py", line 552, in _prepare_linked_requirement
    self.download_dir, hashes
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\operations\\prepare.py", line 243, in unpack_url
    hashes=hashes,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\operations\\prepare.py", line 102, in get_http_url
    from_path, content_type = download(link, temp_dir.path)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\network\\download.py", line 157, in __call__
    for chunk in chunks:
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\cli\\progress_bars.py", line 152, in iter
    for x in it:
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\network\\utils.py", line 86, in response_chunks
    decode_content=False,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py", line 443, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the 'E:\\Project\\PycharmProjects\\P-001\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.

尝试升级pip,结果pip也升不了级,并且报以下错:

C:\\Users\\Administrator>E:\\Project\\PycharmProjects\\P-001\\venv\\Scripts\\python.exe -m pip install --upgrade pip
Requirement already satisfied: pip in e:\\project\\pycharmprojects\\p-001\\venv\\lib\\site-packages (21.1.2)
ERROR: Exception:
Traceback (most recent call last):
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\cli\\base_command.py", line 180, in _main
    status = self.run(options, args)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\cli\\req_command.py", line 204, in wrapper
    return func(self, options, args)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\commands\\install.py", line 319, in run
    reqs, check_supported_wheels=not options.target_dir
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\resolver.py", line 128, in resolve
    requirements, max_rounds=try_to_avoid_resolution_too_deep
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 473, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 341, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\resolvers.py", line 172, in _merge_into_criterion
    if not criterion.candidates:
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\resolvelib\\structs.py", line 139, in __bool__
    return bool(self._sequence)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 143, in __bool__
    return any(self)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 129, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\found_candidates.py", line 74, in _iter_built_with_inserted
    for version, func in infos:
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\resolution\\resolvelib\\factory.py", line 272, in iter_index_candidate_infos
    hashes=hashes,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\package_finder.py", line 879, in find_best_candidate
    candidates = self.find_all_candidates(project_name)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\package_finder.py", line 824, in find_all_candidates
    page_candidates = list(page_candidates_it)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\sources.py", line 134, in page_candidates
    yield from self._candidates_from_page(self._link)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\package_finder.py", line 783, in process_project_url
    html_page = self._link_collector.fetch_page(project_url)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\collector.py", line 512, in fetch_page
    return _get_html_page(location, session=self.session)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\collector.py", line 422, in _get_html_page
    resp = _get_html_response(url, session=session)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\index\\collector.py", line 137, in _get_html_response
    "Cache-Control": "max-age=0",
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\requests\\sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_internal\\network\\session.py", line 449, in request
    return super().request(method, url, *args, **kwargs)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\requests\\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\requests\\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\cachecontrol\\adapter.py", line 53, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\requests\\adapters.py", line 449, in send
    timeout=timeout
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\connection.py", line 506, in _connect_tls_proxy
    ssl_context=ssl_context,
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\util\\ssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "E:\\Project\\PycharmProjects\\P-001\\venv\\lib\\site-packages\\pip\\_vendor\\urllib3\\util\\ssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ssl.py", line 773, in __init__
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the 'E:\\Project\\PycharmProjects\\P-001\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.

解决方法是:此处的pip用不了,那我们就使用python的安装文件下的pip呗~
为防止出现不可预料的意外,最好以管理员身份运行cmd,如下图所示:

因为已经设置了环境变量,所以直接输入命令“pip install sympy”,即可安装sympy,如下图所示:

C:\\Users\\Administrator>pip install sympy
Collecting sympy
  Downloading https://files.pythonhosted.org/packages/78/43/33c5a5e7fbafbf51520f4e09cb0634a1ca1d4cd5469c57967e43183d7a42/sympy-1.9-py3-none-any.whl (6.2MB)
    100% |████████████████████████████████| 6.2MB 9.5kB/s
Collecting mpmath>=0.19 (from sympy)
  Downloading https://files.pythonhosted.org/packages/d4/cf/3965bddbb4f1a61c49aacae0e78fd1fe36b5dc36c797b31f30cf07dcbbb7/mpmath-1.2.1-py3-none-any.whl (532kB)
    100% |████████████████████████████████| 542kB 10kB/s
Installing collected packages: mpmath, sympy
Successfully installed mpmath-1.2.1 sympy-1.9
You are using pip version 18.1, however version 21.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

然后新添加一个解释器,选择自己单独安装的python,对于博主而言,路径如下:
C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages




C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\python.exe

然后选择这个新添加的解释器及运行环境:

选择好之后就有sympy了~
并且可正常导入和使用,如下图所示:

以上是关于pycharm工程中的pip用不了怎么办?的主要内容,如果未能解决你的问题,请参考以下文章

pycharm下载plt库下载不了

在PyCharm中遇到pip失效时的解决方案以及其他发现pip安装失败不了这样处理

pycharm中lxml安装失败

pycharm代码运行不了,求大佬帮忙看看

pycharm怎么导入库

PyCharm更换pip源为国内源模块安装PyCharm依赖包导入导出教程