'python3.6 -m pip install --upgrade azure-cosmos > 4.2.0 > from azure.cosmos import CosmosClient > ModuleNotFoundError: No module named 'azure.cosmos'
When I try to import CosmosClient from azure.cosmos, I get a ModuleNotFoundError, like the azure-cosmos library was not installed:
$ python3.6 -c "from azure.cosmos import CosmosClient"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'azure.cosmos'
I'm using Linux with Python 3.6 I am trying to import CosmosClient from the azure-cosmos library. I have installed azure-cosmos in version 4.2.0 using python3.6 -m pip install --upgrade azure-cosmos, then:
$ python3.6 -m pip show azure-cosmos
Name: azure-cosmos
Version: 4.2.0
Summary: Microsoft Azure Cosmos Client Library for Python
Home-page: https://github.com/Azure/azure-sdk-for-python
Author: Microsoft Corporation
Author-email: [email protected]
License: MIT License
Location: /usr/local/lib/python3.6/dist-packages
Requires: six, azure-core
The /usr/local/lib/python3.6/dist-packages folder is present in sys.path:
$ python3.6 -c "import sys; print([p for p in sys.path])"
['', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/lib/python3/dist-packages']
This is similar to a problem I had yesterday, where a lower version of the library from global dist-packages was shadowing a higher version in local dist-packages, but this time the azure-cosmos package is not installed globally in dist-packages:
$ apt-get remove python3-azure-cosmos
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3-azure-cosmos
What am I missing here?
Solution 1:[1]
A possible workaround (but not a solution) to this and another similar issue I had a day before is to just use a python virtual environment, e.g. using pipenv:
$ pip3 install --upgrade pipenv
$ pipenv install azure-cosmos
$ pipenv run python -c "from azure.cosmos import CosmosClient"
And we have empty output so there is no import error anymore, meaning that it works.
Solution 2:[2]
Did you try pip list to see all the packages you installed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mrc |
| Solution 2 | xyan |
