Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.92k stars 3.77k forks source link

AttributeError: module 'asyncio' has no attribute 'coroutine' #375

Closed galac-tech closed 8 years ago

galac-tech commented 8 years ago

So, I am having trouble trying to get this working. I am using the basic_bot.py example and I keep getting this crazy long error log:

Traceback (most recent call last):
  File "/Users/MacHacker/Code/discord/test.py", line 1, in <module>
    import discord
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/client.py", line 28, in <module>
    from .user import User
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/user.py", line 27, in <module>
    from .utils import snowflake_time
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/utils.py", line 31, in <module>
    import asyncio
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/__init__.py", line 21, in <module>
    from .base_events import *
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 20, in <module>
    import inspect
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/inspect.py", line 35, in <module>
    import dis
  File "/Users/MacHacker/Code/discord/dis.py", line 2, in <module>
    from discord.ext import commands
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/ext/commands/__init__.py", line 13, in <module>
    from .bot import Bot, when_mentioned, when_mentioned_or
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 35, in <module>
    from .core import GroupMixin, Command, command
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/ext/commands/core.py", line 35, in <module>
    from . import converter as converters
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/ext/commands/converter.py", line 164, in <module>
    class InviteConverter(Converter):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/discord/ext/commands/converter.py", line 165, in InviteConverter
    @asyncio.coroutine
AttributeError: module 'asyncio' has no attribute 'coroutine'

It would seem something is wrong with the package, maybe?

I'm running OS X Yosemite 10.10.5 with Python 3.5.2.

Any help or tips would be appreciated. Thanks!

byronvanstien commented 8 years ago

In python 3.5 you're supposed to be using

async def function_name(arguments):
    await function()

Not

@asyncio.coroutine
def function_name(arguments):
    yield from function()

Btw, reinstall discord.py

sgtlaggy commented 8 years ago

The problem here is most likely with your Python install. Reinstalling 3.5 should solve this. Or you have a module in your bot's directory named asyncio.py.

galac-tech commented 8 years ago

@GetRektByMe I saw that and I tried to go through the package and change all the instances of @asyncio.coroutine to async def... along with all the yield from's to await but I started to get an error that await and async were being used improperly or something... Also I removed discord.py and reinstalled it twice after getting Python 3.5.2, didn't help :(

@mikevb1 I had Python 3.5.1, which I updated to 3.5.2 about 30 minutes before I made this post, but it made no difference.

Should I try to use an older version of Python that is compatible with @asyncio.coroutine?

Thanks for the help!

byronvanstien commented 8 years ago

Python is forwards compatible, 3.4's @asyncio.coroutine should work... You've messed up your python install somehow unless you have a file called asyncio.py in your project. Send a screenshot of your project structure

Rapptz commented 8 years ago

Your python install is borked. Don't modify the library files.

galac-tech commented 8 years ago

@GetRektByMe So I found a __pycache__ folder and deleted it. Now I'm not getting that long error log but I do get this :

async def on_ready():
    ^
SyntaxError: invalid syntax

Thanks for the help so far, any ideas?

function with error

Rapptz commented 8 years ago

http://discordpy.readthedocs.io/en/latest/faq.html#i-get-a-syntaxerror-around-the-word-async-what-should-i-do

galac-tech commented 8 years ago

@Rapptz Thanks! It is working now! Also thanks @GetRektByMe for getting me to look at the project structure!

So, after clearing the cache, the problem was: I was using Sublime Text to run the Python code but it was still executing the files with Python 3.4

Thanks for all the help 👍