简体   繁体   中英

'import discord' not working in Python 3.5

I try to import discord in python 3.5, but I get the following traceback:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
  File "C:\Python\Python35-32\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Python\Python35-32\lib\site-    packages\discord\client.py", line 42, in <module>
    from .voice_client import VoiceClient
  File "C:\Python\Python35-32\lib\site-    packages\discord\voice_client.py", line 65, in <module>
    from .gateway import *
  File "C:\Python\Python35-32\lib\site-    packages\discord\gateway.py", line 31, in <module>
    import aiohttp
  File "C:\Python\Python35-32\lib\site-    packages\aiohttp\__init__.py", line 10, in <module>
    from .protocol import *  # noqa
  File "C:\Python\Python35-32\lib\site-    packages\aiohttp\protocol.py", line 11, in <module>
    from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'

I installed discord inside Python35-32\\Scripts using pip install discord . Additionally, I installed asyncio using pip install asyncio in the same directory.

The error pops up in my command prompt, when I type in "python", wait for it to open, and then type "import discord". I'm saying that just to be clear that it's not a "I have a file named XXX.py which clashes with something from the discord library" type of error.

Based on the comments you have added and the line

    File "C:\Python\Python35-32\lib\site-    packages\aiohttp\protocol.py", line 11, in <module>
    from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'

The problem seems to be that 'format_date_time' could not be imported from the built in library wsgiref. Turns out that the file ...\\Python35-32\\lib\\wsgiref\\handlers.py was completely empty indicating that something corrupted your python installation.

Two possible solutions:

  1. Reinstall your python completely which also has the benefit of solving other potential corruptions that you might not have noticed yet (Note that the underlying cause for this corruption remains unknown)

  2. Go into the Cython git and copy the contents of the handlers.py into the local file. This is a very specific solution however and you should be aware that other parts of your python installation might also be corrupt.

也许您想pip install discord.py而不是discord吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM