python - 导入错误: cannot import name 'Deque'

标签 python python-3.x heroku discord discord.py

我正在尝试在 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

关于python - 导入错误: cannot import name 'Deque' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60011092/

相关文章:

python - 在 Django 中链接静态文件目录

python - 检测同一 View 的两个不同拍摄图像之间的差异

python-3.x - 如何使用 python 中的模型将输入的 0 值替换为预测值

python-3.x - 在 HPC 集群上使用 Python 多处理

ruby-on-rails - Heroku rake 迁移

ssl - Heroku 上的空操作测功机

python - Django 模型分组依据

python - 通过日志记录更新 QTextEdit 时 PyQt5 程序崩溃

python - 如何在 pandas 中将字符串分解为列?

git - Heroku 推送被拒绝,子模块安装失败