16

I'm a fairly new to Python and I am trying to enter the following code:

from websocket import create_connection as cc
import json, time

I want to look at BTC and LTC stocks in a live feed type-fashion but I keep getting this error:

ModuleNotFoundError: No module named 'websocket'

I've been looking around and it seems that a common solution is:

pip install websocket

that just didn't connect with me. Most sites say install this and just have the above code but I have no idea where to install it or what to do with it.

1
  • 1
    avoid inline imports! Commented Dec 6, 2017 at 6:29

10 Answers 10

16

First, you need to install pip if you don't have it. Type pip in your terminal or cmd to see if it is installed. Or else, install it first by downloading get-pip.py and executing it.

Then you do pip install websocket, which will install the module for you.

2
  • do i put all of this, including the get-pip.py in the terminal or cmd? Commented Dec 6, 2017 at 9:52
  • 1
    Go to this link save it locally. Then type in your terminal/cmd, cd into the downloaded file's directory, python get-pip.py. It should install pip for you. Then all you need to do is just pip install websocket.
    – thuyein
    Commented Dec 7, 2017 at 2:10
7

If the websocket and websocket-client doesn't work, try:

pip install websocket_client

It works for me.

5

Worked on my machine using

pip install "websockets==8.1"
1
  • 1
    this command working well Commented Jun 3, 2022 at 8:51
4

you can also try

pip install websocket-client
4

There seem to be 2 packages in python 3.7: websocket, and websockets. In my case, I tried to install the former but it had to be the latter. Wasted half an hour of my life on that. People who get here might be in the same bag.

1
  • I tried every combination of pip/pip3 install websocket/websockets/websocket-client/websocket_client, no luck
    – Liam
    Commented May 12, 2021 at 20:38
0

For me, nothing worked except Pycharm editor showed a suggestion 'install websocket' which worked(in the import line).

0

Try with pip install websockets that's work for me!

0

If you are using pip, as mentioned it is pip install websockets

However, if you are using conda, use: conda install -c conda-forge websockets

0

This worked for me:

conda install -c conda-forge websockets
0

use pip3 install websockets

That works instead of pip install websockets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.