python-socketio: AttributeError: module 'socketio' has no attribute 'Client'

I’m trying to use the Socket.io client. I’ve seen #190 and #198 and I’ve made sure I’ve installed python-socketio and don’t have socketio installed.

I run the test program:

print("one")

import socketio

print("two")
print(socketio)
print(dir(socketio))
print("---")

sio = socketio.Client()

print("three")

and I get the output:

$ python3 socket.py
one
one
two
<module 'socketio' from '/usr/local/lib/python3.7/site-packages/socketio/__init__.py'>
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'sys']
---
Traceback (most recent call last):
  File "socket.py", line 3, in <module>
    import socketio
  File "/usr/local/lib/python3.7/site-packages/socketio/__init__.py", line 3, in <module>
    from .client import Client
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 5, in <module>
    import engineio
  File "/usr/local/lib/python3.7/site-packages/engineio/__init__.py", line 7, in <module>
    from .asyncio_server import AsyncServer
  File "/usr/local/lib/python3.7/site-packages/engineio/asyncio_server.py", line 1, in <module>
    import asyncio
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/__init__.py", line 8, in <module>
    from .base_events import *
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 23, in <module>
    import socket
  File "/Users/sampo/Odysseus/odysseus-python/socket.py", line 10, in <module>
    sio = socketio.Client()
AttributeError: module 'socketio' has no attribute 'Client'

I have no idea why one is printed out twice.

I’m running on MacOS Mojave with Python 3.7.2 installed with Homebrew. Some diagnostics:

$ python3 --version
Python 3.7.2

$ pip3 freeze
python-engineio==3.4.3
python-socketio==3.1.2
six==1.12.0

$ pip3 show python-socketio
Name: python-socketio
Version: 3.1.2
Summary: Socket.IO server
Home-page: http://github.com/miguelgrinberg/python-socketio/
Author: Miguel Grinberg
Author-email: miguelgrinberg50@gmail.com
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Requires: python-engineio, six
Required-by:

$ pip3 show socketio

$ head -n20 /usr/local/lib/python3.7/site-packages/socketio/client.py | tail -n7

class Client(object):
    """A Socket.IO client.

    This class implements a fully compliant Socket.IO web client with support
    for websocket and long-polling transports.

$ tail /usr/local/lib/python3.7/site-packages/socketio/__init__.py

__version__ = '3.1.2'

__all__ = ['__version__', 'Client', 'Server', 'BaseManager', 'PubSubManager',
           'KombuManager', 'RedisManager', 'ZmqManager', 'Namespace',
           'ClientNamespace', 'WSGIApp', 'Middleware']
if AsyncServer is not None:  # pragma: no cover
    __all__ += ['AsyncClient', 'AsyncServer', 'AsyncNamespace',
                'AsyncClientNamespace', 'AsyncManager', 'AsyncRedisManager',
                'ASGIApp', 'get_tornado_handler']

Thanks for any assistance!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

@miguelgrinberg I see what happened. I opened https://python-socketio.readthedocs.io/en/latest/intro.html# and didn’t find any install command . So instead I inferred this import socketio to be pip install socketio which seems to be either deprecated or something unrelated. Fixed by running pip install python-socketio

You can’t have a file named socket.py in your top-level directory, because it shadows the socket module from the Python standard library. Rename that file to some other name and try again.

Try these:

python-engineio==3.11.2
python-socketio==4.4.0

@Rolandisimo Are you sure the package python-socketio is installed? Check the output of pip freeze. I bet you don’t have it and instead have something other unrelated socketio package.

Hi, Please help me, since I am facing the similar issue. Traceback )most recent call last): File “singleboard.py”, line 52, in <module> @socketio.event AttributeError: ‘SocketIO’ object has no attribute ‘event’

Please suggest! Thanks.