python - ImportError:无法导入名称“双端队列”
问题描述
我正在尝试在 Heroku 上托管我的 Discord.py 机器人。当我的机器人启动时出现以下错误:
2020-01-31T20:49:31.501236+00:00 heroku[worker.1]: State changed from starting to up
2020-01-31T20:49:32.858327+00:00 heroku[worker.1]: State changed from up to crashed
2020-01-31T20:49:32.839912+00:00 heroku[worker.1]: Process exited with status 1
2020-01-31T20:49:32.766672+00:00 app[worker.1]: Traceback (most recent call last):
2020-01-31T20:49:32.766696+00:00 app[worker.1]: File "bot.py", line 3, in <module>
2020-01-31T20:49:32.766815+00:00 app[worker.1]: import discord
2020-01-31T20:49:32.766819+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/__init__.py", line 23, in <module>
2020-01-31T20:49:32.766952+00:00 app[worker.1]: from .client import Client
2020-01-31T20:49:32.766954+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 35, in <module>
2020-01-31T20:49:32.767061+00:00 app[worker.1]: import websockets
2020-01-31T20:49:32.767062+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/__init__.py", line 3, in <module>
2020-01-31T20:49:32.767164+00:00 app[worker.1]: from .auth import *
2020-01-31T20:49:32.767166+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/auth.py", line 15, in <module>
2020-01-31T20:49:32.767263+00:00 app[worker.1]: from .server import HTTPResponse, WebSocketServerProtocol
2020-01-31T20:49:32.767265+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/server.py", line 49, in <module>
2020-01-31T20:49:32.767374+00:00 app[worker.1]: from .protocol import WebSocketCommonProtocol
2020-01-31T20:49:32.767375+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/protocol.py", line 18, in <module>
2020-01-31T20:49:32.767487+00:00 app[worker.1]: from typing import (
2020-01-31T20:49:32.767492+00:00 app[worker.1]: ImportError: cannot import name 'Deque'
我该如何解决?
解决方案
该websockets
模块与 python 3.6.0 不兼容
我自己重现了这个问题:
C:\Users\Me>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Me>pip install websockets
Collecting websockets
Downloading https://files.pythonhosted.org/packages/6a/bd/8555c65b3fca7310b2601d0957b36511c3c3c2e8a93a6d3f90c671b70c6a/websockets-8.0.2-cp36-cp36m-win_amd64.whl (65kB)
|████████████████████████████████| 71kB 918kB/s
Installing collected packages: websockets
Successfully installed websockets-8.0.2
WARNING: You are using pip version 19.1.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\Me>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import websockets
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\websockets\__init__.py", line 3, in <module>
from .auth import *
File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\websockets\auth.py", line 15, in <module>
from .server import HTTPResponse, WebSocketServerProtocol
File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\websockets\server.py", line 49, in <module>
from .protocol import WebSocketCommonProtocol
File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\websockets\protocol.py", line 18, in <module>
from typing import (
ImportError: cannot import name 'Deque'
它适用于 3.6.1: https ://repl.it/repls/NotableDarkorchidBloatware
推荐阅读
- awk - awk if/else 抛出错误
- php - 获取使用 ldap 进行 SSO 登录 windows 的用户
- linux - 如何在 linux 中解压 .vw.gz 文件?
- apache-spark - 为什么在 hadoop 上使用 H2O 时看不到 Yarn 中的特定任务执行?
- javascript - Angular js将字符串属性转换为json对象内的布尔值
- javascript - Meteor 1.6 在客户端和服务器端进行同步调用
- python - Google Flex App Engine 未写入 Cloud SQL 数据库
- python - 从未调用 Django m2m_changed 信号
- css - 是否可以在不使用 webpack 编译为 css 的情况下提取 sass?
- java - 在 Windows 命令行参数中使用空格