VSCode出现ModuleNotFoundError:No module named numpy错误

本人在安装VSCode和python之后,在编写代码块“import numpy as np”时,发现会一直提示错误“ModuleNotFoundError: No module named 'numpy”,在解决过程中,有如下几种方法:
一、pip install numpy

PS F:\py代码> pip install numpy
Collecting numpy
  Downloading numpy-1.18.5-cp38-cp38-win_amd64.whl (12.8 MB)
     |███▌                            | 1.4 MB 4.9 kB/s eta 0:38:28ERROR: Exception:
Traceback (most recent call last):
  File "f:\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 425, in _error_catcher
    yield
  File "f:\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "f:\python\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "f:\python\lib\http\client.py", line 454, in read
    n = self.readinto(b)
  File "f:\python\lib\http\client.py", line 498, in readinto
    n = self.fp.readinto(b)
  File "f:\python\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
  File "f:\python\lib\ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "f:\python\lib\ssl.py", line 1099, in read
    return 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 "f:\python\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
    status = self.run(options, args)
  File "f:\python\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
    return func(self, options, args)
  File "f:\python\lib\site-packages\pip\_internal\commands\install.py", line 332, in run
    requirement_set = resolver.resolve(
  File "f:\python\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 179, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "f:\python\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 362, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "f:\python\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 314, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "f:\python\lib\site-packages\pip\_internal\operations\prepare.py", line 467, in prepare_linked_requirement
    local_file = unpack_url(
  File "f:\python\lib\site-packages\pip\_internal\operations\prepare.py", line 255, in unpack_url
    file = get_http_url(
  File "f:\python\lib\site-packages\pip\_internal\operations\prepare.py", line 129, in get_http_url
    from_path, content_type = _download_http_url(
  File "f:\python\lib\site-packages\pip\_internal\operations\prepare.py", line 281, in _download_http_url
    for chunk in download.chunks:
  File "f:\python\lib\site-packages\pip\_internal\cli\progress_bars.py", line 166, in iter
    for x in it:
  File "f:\python\lib\site-packages\pip\_internal\network\utils.py", line 15, in response_chunks
    for chunk in response.raw.stream(
  File "f:\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "f:\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "f:\python\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "f:\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, 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.

用这种方法,可能是因为网络原因,导致时间超出。
二、pip install --default-timeout=1000 numpy
最后用这种方法解决,可能第一次也会出现错误,错误如下:

PS F:\py代码> pip install --default-timeout=1000 numpy
Collecting numpy
  Downloading numpy-1.18.5-cp38-cp38-win_amd64.whl (12.8 MB)
     |██████████████████████████████  | 11.9 MB 9.0 kB/s eta 0:01:39
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.kage versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.                                                                          02a184988cb5ec1ccba9/numpy-1.18.5-cp38-cp38-win_amd64.whl#sha256=3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911
    numpy from https://files.pythonhosted.org/packages/22/cb/21a148329591931d8764e7ef49cb19586dd5b5e002a184988cb5ec1ccba9/numpy-1.18.5-cp38-cp38-win_amd64.whl#sha256=3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911f:
        Expected sha256 3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911f
             Got        64108f9c2ad44cd9d409deb549614d755e03fe7f784712a0d7eb3304381ce473

多试几次,即可。本人安装3次左右,才安装成功,并测试成功,成功如下:

PS F:\py代码> pip install --default-timeout=1000 numpy
Collecting numpy
  Downloading numpy-1.18.5-cp38-cp38-win_amd64.whl (12.8 MB)
     |████████████████████████████████| 12.8 MB 8.8 kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.5

三、也可以使用国内镜像
如下载pymongo,可以用如下代码:
pip install pymongo -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

  • 11
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZhInen丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值