Python Forum
how to find module in installed packages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to find module in installed packages
#1
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?
Reply
#2
(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.
Reply
#3
import apliclient
help(apliclient)
Reply
#4
Thanks guys, i'm not at my PC anymore, will test it tomorrow
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pip lists the module but python does not find it Dato 2 1,269 Apr-13-2023, 06:40 AM
Last Post: Dato
  ModuleNotFound but pip shows module installed biscotty666 2 1,546 Jul-14-2022, 05:17 PM
Last Post: Axel_Erfurt
  'no module named' when creating packages mbastida 4 3,983 Nov-30-2021, 10:43 AM
Last Post: Gribouillis
  No module named 'pysolar' - even tough pysolar is installed - What am I doing wrong? Jghurt 5 4,207 May-08-2021, 07:03 PM
Last Post: Jghurt
  unable to find module in su mode? korenron 2 1,918 Jan-10-2021, 07:41 PM
Last Post: Gribouillis
  Cannot find module 'torch' ErnestTBass 6 3,618 Oct-13-2020, 05:33 PM
Last Post: ErnestTBass
  Unable to find an existing module arbiel 2 4,951 Apr-11-2020, 07:12 PM
Last Post: arbiel
  how to import a module which is installed to personal folder using pip install --pre? geekgeek 2 2,417 Mar-09-2020, 02:38 PM
Last Post: geekgeek
  bs4 beautifulsoup4 "module not found" but I confirmed it is installed mjglsn 1 16,364 Feb-01-2020, 12:12 AM
Last Post: metulburr
  [split] Windows can't find installed packages deep_logic 11 5,448 Nov-26-2019, 10:39 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020