IoT user
IoT user

Reputation: 1300

No module named 'azure.eventhub'; 'azure' is not a package

I am trying to execute this example using Python 3.7 with Pycharm and azure-eventhub 1.2.0 package.

When I try to run it, I get this error:

ModuleNotFoundError: No module named 'azure.eventhub'; 'azure' is not a package

This is the problematic line:

from azure.eventhub import EventHubClient, Receiver, Offset

What could be happening?

This is my project interpreter

project interpreter

Using pip freeze:

pip freeze

Upvotes: 0

Views: 5104

Answers (1)

Peter Pan
Peter Pan

Reputation: 24148

As I known, there is a case which will cause your issue.

The Python Interpreter searches the available packages, objects and methods in the paths of sys.path in order, you can print the value of the sys.path variable to see the order after import sys.

So if there is a Python script named azure.py prior to the real azure package, you will get the issue ModuleNotFoundError: No module named 'azure.eventhub'; 'azure' is not a package.

Here is my steps to reproduce this issue.

  1. I created a Python script named azure.py in the current path which only have one line code print('pseudo azure package'). enter image description here
  2. Then, I opened my Python interpreter in the current path and type from azure.eventhub import EventHubClient, Receiver, Offset, then to get the issue as below. enter image description here

It also will happen in Pycharm, even using virtualenv, please check whether exists a file called azure.py or azure.pyc in your current path or the paths in the order of sys.path list.

Upvotes: 5

Related Questions