简体   繁体   中英

ModuleNotFoundError: No module named 'websocket' even though I installed pip install websocket

I am trying to run some code that has 'import websocket' however I am getting the error: ModuleNotFoundError: No module named 'websocket'

I have Python 3.7.3 and I am running in Spyder (if that makes a difference).

So from other questions/answers I found on here, in my cmd I ran pip install websocket and then also pip install websocket-client when the first one didn't run.

I am still getting the ModuleNotFoundError . Does it matter the location/folder of the code or where I install the pip command in cmd?

My python code starts with these import statements:

import json
import websocket
import traceback
import helper
import ssl
import time as time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D

In cmd I ran:

C:\Users\myname>pip install websocket 

and also:

C:\Users\myname>pip install websocket-client

The error I am getting is:

File "C:/Users/micki/Downloads/Derbit-Volatility-Visulization-master/Derbit-Volatility-Visulization-master/Volatility Surface Class.py", line 2, in <module>
    import websocket

ModuleNotFoundError: No module named 'websocket'

Not sure, as you did not cover how you installed and are using Spyder, though I think it is probably an issue with your environment. You might also find that you are missing the module "helper" as well. There's two easy options as follows:

  1. If you installed and are using Spyder via conda or anaconda, follow their documentation on installing websocket-client to the correct environment found here .
  2. The second option (the preferred option IMHO, as you can use any IDE or text editor going forward), regardless of how you installed Spyder, would be to create a python virtual environment python3 -m venv /path/to/new/virtual/environment , pip install all your dependencies in said environment, then link Spyder's interpreter to the interpereter that was installed when you made the environment. In Spyder, go to Tools -> Preferences -> Python interpreter -> check the "Use the following Python interpreter:" radio button and enter the path to the interpreter from the environment you just created. For reference, see docs on making and using a python venv here .

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

pip install websocket_client

This solved my issue:

sudo pip install websocket-client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM