【问题标题】:Concurrent.futures ProblemsConcurrent.futures 问题
【发布时间】:2021-05-04 04:00:27
【问题描述】:

所以我有这段代码需要使用 Concurrent.futures 模块,由于某种原因它告诉我它不存在。我已经查过了,我找不到问题所在。我已经尝试安装我需要的工具,我认为是这种情况,但我只能下载其中一个。 错误信息:

从 concurrent.futures 导入 ProcessPoolExecutor ModuleNotFoundError:没有名为“concurrent.futures”的模块; 'concurrent' 不是一个包

我的代码:

import requests, time
from concurrent.futures import ProcessPoolExecutor

sites = ["http://www.youtube.com"]

def get_one(site):
    resp = requests.get(site)
    size = len(resp.content)
    print(f"download {site} bytes from {site}")
    return size

def main():
    total_size = 0
    start = time.perf_counter()
    with ProcessPoolExecutor as exec:
        total_size = sum(exec.map(get_one, sites))
    end = time.perf_counter()
    for site in sites:
        
        total_size += size
        #print(f"downlded {size} bytes from {site}")
    #end = time.perf_counter()
    
    print(f"elapsed time: {end - start} seconds")
    print (f"downloaded a totla of {total_size} bytes")
    
    
if __name__== "__main__":
    main()

我知道当我说“来自”时通常应该有一个文件,但我查找的所有内容都说 concurrent.futures 是 python 的一部分,但由于某种原因我的不能正常工作。如果它在那里,我必须安装它吗?

【问题讨论】:

  • 如果去终端,运行python -v然后输入>>> import concurrent你会看到类似# code object from '/opt/anaconda3/lib/python3.8/concurrent/__pycache__/__init__.cpython-38.pyc' import 'concurrent' # <_frozen_importlib_external.SourceFileLoader object at 0x7fadd1320430>的东西你能检查一下吗?

标签: python concurrent.futures modulenotfounderror


【解决方案1】:

我发现我的文件夹中有一个名为 concurrent.py 的文件,它搞砸了一切!

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2016-12-03
    • 1970-01-01
    • 2016-11-22
    • 2022-01-10
    • 2021-12-10
    相关资源
    最近更新 更多