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

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

19reactions
Rolandisimocommented, Aug 4, 2019

@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

14reactions
miguelgrinbergcommented, Mar 5, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python3 AttributeError: module 'socketio' has no attribute 'Client'
The common cause of Python mysteriously complaining about a module not having an attribute that it should have is that you've got a...
Read more >
AttributeError: module 'socketio' has no attribute 'Server'
AttributeError : module 'socketio' has no attribute 'Server'. But, if in my local repo, I installed python-socketio in my local repo venv ...
Read more >
module 'socketio' has no module 'client' - Replit
I took this socketio code from newsfilter, however it does not work. Newsfilter says you have to use version 2 of socketio, which...
Read more >
AttributeError: module 'socketio' has no attribute 'Client'
I tried to install python-socketio, upgrade setuptols and everything I already saw in other posts, this code can run on my windows laptop ......
Read more >
The Socket.IO Client — python-socketio documentation
When a server wants to communicate with a client it emits an event. Each event has a name, and a list of arguments....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found