【问题标题】:python3 error, cannot import name 'SimpleQueue'python3错误,无法导入名称'SimpleQueue'
【发布时间】:2015-12-21 19:42:34
【问题描述】:
#!/usr/bin/env python3

import logging; logging.basicConfig(level=logging.INFO)

import asyncio, os, json, time
from datetime import datetime

from aiohttp import web

def index(request):
    return web.Response(body=b'<h1>Awesome</h1>')

@asyncio.coroutine
def init(loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', '/', index)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever()

进程 (28411) 开始... 我(28411)刚刚创建了一个子进程(28412)。 我是子进程(28412),我的父进程是 28411。 回溯(最近一次通话最后): 文件“webApp.py”,第 5 行,在 导入异步、操作系统、json、时间 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/init.py”,第 21 行,在 回溯(最近一次通话最后): 文件“webApp.py”,第 5 行,在 导入异步、操作系统、json、时间 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/init.py”,第 21 行,在 从 .base_events 导入 * 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py”,第 18 行,在 从 .base_events 导入 * 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py”,第 18 行,在 导入并发期货 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/init.py”,第 17 行,在 导入并发期货 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/init.py”,第 17 行,在 从 concurrent.futures.process 导入 ProcessPoolExecutor 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py”,第 54 行,在 从 concurrent.futures.process 导入 ProcessPoolExecutor 文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py”,第 54 行,在 从多处理导入 SimpleQueue 从多处理导入 SimpleQueue ImportError:无法导入名称“SimpleQueue” ImportError: 无法导入名称“SimpleQueue”

【问题讨论】:

  • 可以单独导入多处理库吗?例如,你能运行python3 -c "from multiprocessing import SimpleQueue" 吗?
  • 我可以单独导入多处理库,但是我不能运行 python3 -c "from multiprocessing import SimpleQueue"。

标签: python macos python-3.x


【解决方案1】:

simpleQueue 的 API 似乎发生了变化。

在python3.3中,可以在multiprocessing.SimpleQueue找到(参见文档1

在python3.2中,可以在multiprocessing.queues.SimpleQueue找到(参见文档2

您可能运行的 python 版本早于 3.2,但代码是为较新版本 (>= 3.3) 编写的。您可以尝试修改库以使用旧的导入或升级您的 python 版本。

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 1970-01-01
    • 2017-08-11
    • 2021-02-19
    • 2014-01-29
    • 2016-11-21
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多