ModuleNotFoundError, trying to use binance.websockets - python

Hi I thought this would be pretty straightforwards but I can't figure it out.
It can't find binance.websockets for whatever reason even though it can find binance.client which should be part of the same package?
import config
import os
from binance.client import Client
from twisted.internet import reactor
from binance.websockets import BinanceSocketManager
Running this import code gives this error
Traceback (most recent call last):
File "/home/lucho/Documents/cryptoAPIs/binance/importconfig.py", line 6, in <module>
from binance.websockets import BinanceSocketManager
ModuleNotFoundError: No module named 'binance.websockets
To get the library I installed with pip3
pip3 install python-binance
pip3 install binance-api

The BinanceSocketManager is no longer in the websockets file. Change your import to this:
from binance.streams import BinanceSocketManager
This will fix the issue

use this " pip install python-binance==0.7.9 "

If you look into the breaking changes on version 1.0.1 they mention they changes Websockets, so that is probably what you are hitting.
I would just reinstall the latest version "pip install python-binance" and use the up to date examples on their repo:
https://github.com/sammchardy/python-binance

Related

Error using azure-eventhubs python example

I'm attempting to use the example code to receive data from Azure Event Hub.
Heres the code
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
logger = logging.getLogger("azure")
ADDRESS = "amqps://mine.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=sadfsafdljksad=<eventhub>"
But I am getting the following error when executing..
Traceback (most recent call last):
File "./recv.py", line 5, in <module>
from azure.eventhub import EventHubClient, Receiver, Offset
ImportError: cannot import name 'EventHubClient'
Any assistance will be appreciated.
I think you actually installed azure-eventhub package, version 5.0.0. But EventHubClient does not exist in 5.0.0 version, it exists in azure-eventhub package, version 1.3.3 or below.
By default, when you install the azure eventhub package for python using this command pip install azure-eventhub, it will automatically install the latest version 5.0.0. So this sentence from azure.eventhub import EventHubClient, Receiver, Offset will throw the error ImportError: cannot import name 'EventHubClient'
You can check the version of the package by open cmd -> input command pip show azure-eventhub. Screenshot as below:
There are 2 solutions:
Solution 1: keep using the 5.0.0 version, then you should re-write your code and follow the examples in this doc.
Solution 2: If you want to use the current code which includes from azure.eventhub import EventHubClient, Receiver, Offset, you should first uninstall the 5.0.0 version of azure-eventhub, then reinstall the 1.3.3 version by using this command pip install azure-eventhub==1.3.3
Using this solution works fine
reinstall the 1.3.3 version by using this command pip install azure-eventhub==1.3.3

ImportError: cannot import name 'ServiceAccountCredentials' from 'oauth2client.service_account'

I'm trying to follow along a tutorial on pulling in Google Analytics data using Python.
Having followed the steps throughout the tutorial, when I call the script I get the error message in the title:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredential
Traceback (most recent call last):
File "ga.py", line 4, in
from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name 'ServiceAccountCredentials' from 'oauth2client.service_account'
I was reading this SO post after some Googling.
I tried changing my package version:
pip install oauth2client==1.5.2
I tried adding new packages per the answers on that post:
pip install pyopenssl
pip install pycrypto
pip install httplib2
pip install oauth2client
pip install ssl
In each case I encountered the same message after trying to run ga.py:
(zen_ga) Macs-MacBook:zen_ga macuser$ python ga.py
Traceback (most recent call last):
File "ga.py", line 4, in
from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name 'ServiceAccountCredentials' from 'oauth2client.service_account'
How can I import ServiceAccountCredentials from oauth2client.service_account?
First, the class you are trying to import is called ServiceAccountCredentials, not ServiceAccountCredential. So try this instead: from oauth2client.service_account import ServiceAccountCredentials.
oauth2client 1.5.2 does not include ServiceAccountCredentials. Use a more recent version to use it - the latest version is 4.1.3.
Finally, you should note that oauth2client is deprecated, and it is now recommended to use google-auth instead.
My 2cents:
For this to work I had to install and update these packages either
-from WITHIN the NORMAL TERMINAL with PLAIN PYTHON, no distribution such as Conda(dont forget to set Path-Variable):
py -m pip install google-api-python-client
py -m pip install oauth2client
-or from WITHIN the CONDA TERMINAL with:
pip install google-api-python-client oauth2client
pip install --upgrade oauth2client #important
this did NOT WORK when I tried to install and update from jupyter notebook with pip
It works if you import the module alone and then call the class in your code.
Change the import line to:
from oauth2client import service_account
and call the class with the module prefixed like so:
service_account.ServiceAccountCredentials()

Python can't find installed module slackclient on MacOs. Any suggestions?

I'm developing a slackbot. After importing slackclient, I got ModuleNotFoundError: No module named 'slackclient'.
I tried all the options and followed suggestions showed in the post here- Python can't find installed module ('slackclient'). By those suggestions, I installed slack but got the following error while importing WebClient.
>>> from slack import WebClient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'WebClient' from 'slack' (<path_to _venv>/.venv/lib/python3.7/site-packages/slack/__init__.py)
I checked the slack version that seems like ok
slack 0.0.2
Any suggestions what could I be doing wrong?
Using slackclient version 2
$ pip install slackclient --upgrade
$ pip freeze
slackclient==2.1.0
from slack import WebClient
OR, Using slackclient version 1
$ pip install slackclient==1.3.1
from slackclient import SlackClient
there seems to be a conflict between slack versions and imports. If you are using slack >= 0.0.2 and slackclient >= 0.36.2, try this instead:
from slack.web.client import WebClient
you can check that WebClient class is defined in that directory.
I was able to get it to work by using
from slack.web.client import WebClient
The current version of slackclient for Python3 is 2.1.0.
To upgrade your environment run:
$ pip3 install slackclient --upgrade
You find the latest slackclient here.

ImportError: cannot import name 'InsecureRequestWarning' (PYTHON3 | RPI3 | gTTS)

I'm having trouble using gTTS (Google Text to Speech) on my raspberry Pi 3. I simply did
sudo pip3 install gTTS
to install it. But when I run my code I find this error :
File "interface.py", line 7, in <module>
from gtts import *
File "/usr/local/lib/python3.4/dist-packages/gtts/\__init__.py", line 2, in <module>
from .tts import gTTS
File "/usr/local/lib/python3.4/dist-packages/gtts/tts.py", line 4, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: cannot import name 'InsecureRequestWarning'
To try to solve the problem I did
sudo easy_install --upgrade pip
Then I have uninstalled and installed again gtts but the problem persists.
Thank you very much for your help ! :(
PS : I have installed python-vlc and mutagen to make working gTTS (as I did on a windows device)
Just update requests library
pip install -U requests
Try this way.`
import urllib3`
urllib3.disable_warnings()
Though it doesn't remove the entire warning message, still removes the Insecure Request Warning
Fixed it by running pip install requests==2.6.0
if you face issue with bringing request library to 2.6.0 first remove pyopenssl and then run pip install requests==2.6.0
I don't know if you still want to know but I can partially answer it.
import gtts
why this will work is because gtts automatically imports .tts and gTTS.
This is gtts.__init():
from .version import __version__
from .tts import gTTS
It's the only code in there.
You can go look yourself in the folder:
/usr/local/lib/python3.4/dist-packages/gtts
OR
/usr/local/lib/python2.7/dist-packages/gtts
I am also trying to figure out still, how to use it but otherwise no.

How to install google.cloud with Python pip?

I am relatively new to Python and I am stuck on something which is probably relatively easy to resolve.
I have installed the following packages:
pip install --upgrade google-api-python-client
pip install --upgrade google-cloud
pip install --upgrade google-cloud-vision
In my Python file I have:
import cv2
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
...etc...
And this gives me the error:
Traceback (most recent call last):
File "test.py", line 6, in <module>
from google.cloud import vision
ImportError: No module named 'google.cloud'
What am I missing and where should I look (logs?) to find the answer in the future.
PS:
Pip installs of google-cloud and google-cloud-vision have the output:
Cannot remove entries from nonexistent file /Users/foobar/anaconda/lib/python3.5/site-packages/easy-install.pth
UPDATE:
Running pip freeze doesn't show the packages to be installed...
I had a similar problem. Adding "--ignore-installed" to my pip command made it work for me.
This might be a bug in pip - see this page for more details: https://github.com/pypa/pip/issues/2751
You need to download and install the google-cloud-sdk. Follow this link https://cloud.google.com/sdk/docs/
try this :
from google.cloud.vision import *

Categories