ModuleNotFoundError: No module named 'BybitWebsocket' - python

I'm trying to connect the Bybit websocket to Python via this code.
from BybitWebsocket import BybitWebsocket
ws = BybitWebsocket(wsURL="wss://stream-testnet.bybit.com/realtime",
api_key=None, api_secret=None)
ws.subscribe_instrument_info(symbol="BTCUSD")
while True:
data = ws.get_data("instrument_info.100ms.BTCUSD")
if data:
print(data)
I'm new to Python and websockets so I have no idea why this does not work. I have already pip installed the websocket with the command:
pip install bybit-ws. I get the error: "ModuleNotFoundError: No module named 'BybitWebsocket'". It has probably to do something with a path, but I still can't fix it. Any help?

install bybit-ws is the correct command to install the module you are looking to import, but to make sure that your module is being installed within the correct Python environment, perform:
pip3 install bybit-ws
And then run your code. You might otherwise be well installing it into the system Python (likely Python2, if you are on OSX).
You can check that the module is importable in Python3 if you open a Terminal window and type in:
python3
from BybitWebsocket import BybitWebsocket
If the above succeeds, your import will work if you run it from the Terminal with:
python3 path/to/your/script.py
But if you still get the ModuleNotFound error when you run it from your IDE, then your IDE is configured to execute code within the wrong environment.

Related

Python cannot install graphql

I tried to run a python script on my local machine. Apparently this script stops and throws an error with message "no named module graphql". I tried to do python -m pip install graphql and it also fails with error message "Don't know how to compile graphql/graphql_ext.pyx". A screenshot of the entire error is shown below.
The script and commands are ran with the PowerShell
I use a windows machine
I use Python version "3.10.7"

ModuleNotFoundError: No module named 'IPython', but ipython is installed

I have tried to put this script in the sitecustomize.py file, to be able to see colored error messages in visual studio code.
the script:
import sys
from IPython.core.ultratb import ColorTB
sys.excepthook = ColorTB()
I got the error message above even though I have used pip to install ipython.
EDIT:
I tried to use coloredlogs instead of ipython and it showed me the same message again
The IPython module only works inside iPython, not inside any other IDE/Shell/etc.
Please use the command "pip show ipython" to check the installation location of the module:
(If it does not display the location of the module, it means that the terminal used environment is inconsistent with the selected one.)
Then find the folder of the module in this python environment, try to delete it, and then reinstall it:
Run:
I needed to reinstall python on my computer. there were multiple versions of it, and because of that there were multiple versions of pip

Python gives ImportError: No module named sqlalchemy.util._collections in pycharm

I have installed sqlalchemy in my pathon. Im running python 2.7.15
When I execute my test program it says;
ImportError: No module named sqlalchemy.util._collections
I have installed modules with my python version.
Flask-SQLAlchemy 2.3.2
SQLAlchemy 1.2.2
WHy do I get this error in pycharm. PyCharm run configurations picks correct python version.
In console i tried the import statement it works.
$ python --version
Python 2.7.15
>>> from sqlalchemy.util import _collections
>>>
Why I get this error in pycharm?
First thing I would check is that you're using the correct Python environment in PyCharm.
Use the which python function in your console to see the path to the python executing in your terminal and make sure that it lines up with the path under "External Libraries" in your project view. You may not have sqlalchemy installed on the Python executable in your Pycharm Project. I've had similar issues in the past where I had Python installed alongside Anaconda.
Also consider dropping a requirements.txt file into the root level of your project in Pycharm. If your Python environment doesn't have the library installed it will generally prompt you to install it. Just add in a single line into your requirements.txt file with sqlalchemy. Using echo you could create this file using the following command
echo "sqlalchemy" >> requirements.txt
This is due to Pywren [1] library which could not import some 3 rd party libraries. Not a Python/PyCharm issue
[1]https://github.com/pywren
[2]https://github.com/pywren/pywren/issues/253

Odoo 11 : ImportError No Module Named 'PyPDF2'

I'm using a script to run Odoo11 via pycharm in ubuntu (openerp_openserver script)
When i try to run the program , it fails at some point , when it import pdf module and i have this error :
ImportError No Module Named 'PyPDF2' as you can see in this Image
I Already installed PyPDF2 via this command (i have python3.5 already installed) :
sudo apt-get install python3-pypdf2
So im wondering , what is the problem , why pycharm cannot find and import pypdf2?
Thanks
EDIT :
When i Try to import PyPDF2 using the Python command , i dont have error
Firstly you should try to check whether you can import PyPDF2 library from a python console.
Run from your native console:
python3 -c "import PyPDF2"
If no error message occurs, the problem is not in the library.
Check a path of python interpreter that is used by PyCharm.
Navigate inside PyCharm:
Ctrl-Alt-S > Build, Execution Deployment > Console > Python Console
The path should be to /usr/bin/folder.
If not - change it to a path of the desirable python interpreter that is inside /usr/bin/ folder.
I hope this helps!
Will be good if someone can add a way to solve this type of problem in Windows environment.
For windows you may try installing psycopg2 and requirements again for venv(virtualenvironment.
For psycopg2 install you should follow the steps under "Virtual Environment Installation Notes" title on http://www.stickpeople.com/projects/python/win-psycopg/

ImportError on different server

I have a python script that uses the pytz module and it runs successfully on one server. But I have moved the script to a different server (over SSH), and now when I try to run the code there I get:
ImportError: No module named pytz
Is there an easy way I can get it to run? I believe I don't have the permissions to download new modules...
try to install this module on your new ssh server, by using:
python -m pip install pytz
if you haven't permissions to download any module, try to use a common similar, or compile this script to a .sh or .exe runnable file, on your developer machine.

Categories

Resources