Error: "ModuleNotFoundError: No module named 'websockets.extensions'; 'websockets' is not a package"

9,305 views
Skip to first unread message

Abcde

unread,
Jul 18, 2021, 4:09:47 PM7/18/21
to oTree help & discussion
When I try "otree devserver", the last line of the output is: ModuleNotFoundError: No module named 'websockets.extensions'; 'websockets' is not a package

But I have already installed websockets with "pip install websockets" and "pip3 install websockets"

Following is part of the output of "pip list":
websocket           0.2.1
websocket-client    1.1.0
websockets          8.1

What is the cause of the error and how should I deal with it?

Chris @ oTree

unread,
Jul 18, 2021, 4:17:39 PM7/18/21
to oTree help & discussion
Can you show the full traceback?

Abcde

unread,
Jul 18, 2021, 4:31:10 PM7/18/21
to oTree help & discussion
Open your browser to http://localhost:8000/
To quit the server, press Control+C.

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\Scripts\otree-script.py", line 33, in <module>
    sys.exit(load_entry_point('otree==5.2.7', 'console_scripts', 'otree')())
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\main.py", line 113, in execute_from_command_line
    call_command(cmd, *argv[2:])
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\cli\base.py", line 28, in call_command
    module.Command().outer_handle(args)
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\cli\base.py", line 9, in outer_handle
    return self.handle(**vars(options))
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\cli\devserver_inner.py", line 60, in handle
    run_asgi_server(addr, port, is_devserver=True)
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\cli\prodserver1of2.py", line 11, in run_asgi_server
    run_uvicorn(addr, port, is_devserver=is_devserver)
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\otree\cli\prodserver1of2.py", line 31, in run_uvicorn
    server.run()
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\server.py", line 49, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\server.py", line 56, in serve
    config.load()
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\config.py", line 301, in load
    self.ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\importer.py", line 23, in import_from_string
    raise exc from None
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\importer.py", line 20, in import_from_string
    module = importlib.import_module(module_str)
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 7, in <module>
    from websockets.extensions.permessage_deflate import ServerPerMessageDeflateFactory
ModuleNotFoundError: No module named 'websockets.extensions'; 'websockets' is not a package

Chris @ oTree

unread,
Jul 18, 2021, 5:22:54 PM7/18/21
to oTree help & discussion
I'm not sure, but try this:

pip3 uninstall otree
pip3 uninstall websockets

Then reinstall and try again.

Abcde

unread,
Jul 18, 2021, 6:01:04 PM7/18/21
to oTree help & discussion

I tried multiple times, but it still does not work. 

I tried with both 
pip3 install -U otree and pip3 install otree


When I tried pip3 install -U "otree<5", this error will show up interatively:
Collecting otree<5
  Using cached otree-3.4.0.tar.gz (321 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\administrator\appdata\local\programs\python\python39\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-mo4i5wg8\\otree_aa425551b89c4dc8b68d8e88b260110d\\setup.py'"'"'; __file__='"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-mo4i5wg8\\otree_aa425551b89c4dc8b68d8e88b260110d\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Administrator\AppData\Local\Temp\pip-pip-egg-info-62s8h0xg'
         cwd: C:\Users\Administrator\AppData\Local\Temp\pip-install-mo4i5wg8\otree_aa425551b89c4dc8b68d8e88b260110d\
    Complete output (1 lines):
    This version of oTree is not compatible with Python 3.9.
    ----------------------------------------

Abcde

unread,
Jul 18, 2021, 6:04:13 PM7/18/21
to oTree help & discussion
I am not sure whether the iterative error could provide some hint.

Abcde

unread,
Jul 19, 2021, 2:33:54 AM7/19/21
to oTree help & discussion
Now I started an empty project with sample games. I still get the websocket error after following the instruction here: https://otree.readthedocs.io/en/self/install-nostudio.html?highlight=startproject#run-otree

The output is: 

Chris @ oTree

unread,
Jul 19, 2021, 2:59:55 AM7/19/21
to oTree help & discussion
I'm guessing something went wrong during installation/uninstallation of that package. Try uninstalling and reinstalling python.

Abcde

unread,
Jul 19, 2021, 4:12:11 AM7/19/21
to oTree help & discussion
It works now. Thank you!
Reply all
Reply to author
Forward
0 new messages