python3.6 -m pip install --upgrade azure-cosmos > 4.2.0 > from azure.cosmos import CosmosClient > ModuleNotFoundError: No module named 'azure.cosmos'
Asked Answered
M

2

0

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?

Muriah answered 17/2, 2022 at 16:22 Comment(0)
M
0

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.

Muriah answered 18/2, 2022 at 15:1 Comment(0)
S
-1

Did you try pip list to see all the packages you installed?

Steve answered 17/2, 2022 at 17:47 Comment(1)
Just tried it and it shows the package in version 4.2.0, same as command pip show azure-cosmos that I mentioned. I wouldn't expect pip show and pip list to have different output.Muriah

© 2022 - 2024 — McMap. All rights reserved.