Python Forum

Full Version: how to find module in installed packages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello

i want to run code somebody else wrote a few years ago

no i have trouble run this code

from apiclient.http import BatchHttpRequest
from apiclient.discovery import build
i imported already the package apiclient
although the error says me there is no module named http

Error:
....., line 5, in <module> from apiclient.http import BatchHttpRequest ModuleNotFoundError: No module named 'apiclient.http'
i would like to see, local in my python console which modules are available in the package apiclient

is that possible, and how to do that?

or is there another way to solve this problem?
(May-09-2020, 08:21 PM)keuninkske Wrote: [ -> ]
from apiclient.http import BatchHttpRequest
from apiclient.discovery import build
i imported already the package apiclient
although the error says me there is no module named http

Unfortunately module names (like apiclient) don't have to be unique, and may have a different name than the package they are in.

Quote:i would like to see, local in my python console which modules are available in the package apiclient

You can import the top level package and use dir() to examine what's inside the namespace.

So for the package you've installed, we see this:
>>> import apiclient
>>> dir(apiclient)
['APIClient', 'APIClient_SharedSecret', 'RateLimiter', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'base', 'ratelimiter']
There's no "http" there, so the import will fail.

It appears that the package you're interested in is instead google-api-python-client.

When I install that one instead....
>>> import apiclient
>>> dir(apiclient)
['_SUBMODULES', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'channel', 'discovery', 'errors', 'googleapiclient', 'http', 'iteritems', 'mimeparse', 'model', 'module', 'module_name', 'sample_tools', 'schema', 'sys']
>>> from apiclient.http import BatchHttpRequest
>>>
You can see that http is inside and the import now succeeds.
import apliclient
help(apliclient)
Thanks guys, i'm not at my PC anymore, will test it tomorrow