Discord.py: Cant Import in Python 3.7.0b3

Created on 30 Apr 2018  路  14Comments  路  Source: Rapptz/discord.py

Traceback (most recent call last): File "C:/Users/User/PycharmProjects/Python3.7/Challenge.py", line 1, in <module> import discord File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\__init__.py", line 20, in <module> from .client import Client, AppInfo, ChannelPermissions File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 38, in <module> from .state import ConnectionState File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\state.py", line 36, in <module> from . import utils, compat File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\compat.py", line 32 create_task = asyncio.async
python script:
import discord

duplicate

Most helpful comment

This library does not support 3.7. This error in particular is caused by async becoming a reserved keyword.

Please use Python 3.4-3.6.

All 14 comments

This library does not support 3.7. This error in particular is caused by async becoming a reserved keyword.

Please use Python 3.4-3.6.

when the heck did 3.7 get released

Python 3.7.0 was released on 2018-06-27.

This specific issue was already fixed with https://github.com/Rapptz/discord.py/commit/1863a1c6636f53592519320a173ec9573c090c0b (#995).
On the rewrite branch, it was fixed with https://github.com/Rapptz/discord.py/commit/096584733e8a8025b13f46fa920e18abe19352c1 (#900).

Note, the async branch fix is not on PyPI, and the rewrite branch itself is not on PyPI at all.
Please make sure you're up to date with the most recent development version on either branch before making issues.

Thanks for explaining this, how do I install the async branch to my machine?

python3 -m pip install -U https://github.com/Rapptz/discord.py/archive/async.zip#egg=discord.py[voice] is probably what you want.
This is outlined in the README in reference to the master branch.
Or see any other resources from a simple Google search for something like "pip install from GitHub".

For future questions like this, you should join either the official discord.py server or the Discord API server for help, as the README recommends.

Thanks a lot for not only providing the answer but also teaching me how to do figure stuff out on my own in the future!

I installed the async branch version with python3 -m pip install -U "https://github.com/Rapptz/discord.py/archive/async.zip#egg=discord.py[voice]" (quotes used to make URL cooperate with zsh.) Unfortunately, it looks like this issue is still present.

>>> import discord
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/discord/__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "/usr/lib/python3.7/site-packages/discord/client.py", line 42, in <module>
    from .voice_client import VoiceClient
  File "/usr/lib/python3.7/site-packages/discord/voice_client.py", line 43, in <module>
    import websockets
  File "/usr/lib/python3.7/site-packages/websockets/__init__.py", line 3, in <module>
    from .client import *
  File "/usr/lib/python3.7/site-packages/websockets/client.py", line 12, in <module>
    from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol
  File "/usr/lib/python3.7/site-packages/websockets/protocol.py", line 17, in <module>
    from .compatibility import asyncio_ensure_future
  File "/usr/lib/python3.7/site-packages/websockets/compatibility.py", line 9
    asyncio_ensure_future = asyncio.async           # Python < 3.5
                                        ^
SyntaxError: invalid syntax

Do I need to switch to the rewrite branch and, well, rewrite my application? It looks like Python 3.7 support was added to websockets in version 6.0 but discord.py requires websockets<4.0

@tkdberger I open a pull that should hopfully fix this, either way I fixed it with

pip install --upgrade aiohttp
pip install --upgrade websockets

edited to remove --no-deps

@tkdberger You're right, but this is a separate issue from the discord.py syntax error this issue is about.
The current pinned dependencies on the async branch don't support Python 3.7. See #1401.

Your options are the following:

  • separately upgrade aiohttp and websockets to the latest versions after installing the async branch from GitHub
  • downgrade to Python 3.6
  • switch to the rewrite branch

I don't recommend the first option as the async branch is not guaranteed to work properly with the latest versions of aiohttp and websockets.

@GrayHatter Upgrading aiohttp and websockets without their dependencies shouldn't be necessary, and might actually cause issues within aiohttp itself, since its dependencies have changed as well.

@Harmon758 I dropped the no-deps from my post, I went back and tested it and you're correct, it installs correctly without the --no-deps flag as well.

Is the rewrite branch the new hotness? or is async still the more stable version? It's currently set as the default branch on GH, so I assume it's the one I should be using?

The rewrite branch is hardly new. It's existed for over 1.5 years now.
The async branch is more stable in the sense that the rewrite branch still has occasional breaking changes and is still under development. This is why the async branch is still the default branch; not because the rewrite branch isn't fully functional.
However, the async branch is only getting bug fixes and isn't getting any new feature updates. As such, the rewrite branch is capable of and handles many new aspects of Discord that are not on the async branch. Not only that, but the rewrite branch includes many improvements and refinements, and generally, any bugs are promptly fixed.

You can edit the lines by yourself:
from create_task = asyncio.async to create_task = getattr(asyncio, 'async')
Thanks to stackoverflow by 'vhs': https://stackoverflow.com/questions/51196568/create-task-asyncio-async-syntaxerror-invalid-syntax

As explained, this fixes D.py for 3.7 but the dependencies are not guaranteed to work on 3.7, so don't expect your bot to be stable. We also cannot provide support for someone who was edited the library.

Phython 3.7 version not working discord bot create

Was this page helpful?
0 / 5 - 0 ratings