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
Related
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
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()
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.
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 *
I am currently running python 2.7.
I already installed python-pushover.
But when I try to import following code
from pushover import init, Client'
I get following error
from pushover import init, Client
ImportError: cannot import name init
I have tried
import pushover
from pushover import init, Client
same error.
My guess is that you did pip install pushover. However, this will install a different package from the one you are interested in. Instead, you will need to uninstall that package:
pip uninstall pushover
and install the correct package:
pip install python-pushover
Once you do that, your code should work as expected.