1

I am trying to import this library - https://github.com/abenassi/Google-Search-API

I tried
1. Can not import module search from google module in python
2. Python / ImportError: Import by filename is not supported
3. How to import a module given the full path?

I still can't import

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'google' is not defined

even locally

>>> import imp
>>> google = imp.load_source('google', '/home/arjun/.local/lib/python2.7/site-packages/google/__init__.py')
>>> num_page = 3
>>> search_results = google.search("This is my query", num_page)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'search'
>>> google
<module 'google' from '/home/arjun/.local/lib/python2.7/site-packages/google/__init__.pyc'>
arjun
  • 1,594
  • 16
  • 33

1 Answers1

1

Have you installed it via PIP as described in the README.md on GitHub? I just tryed to run the search function but the pip install failed for me, the import of google doesn't work neither in python3.

But maybe you can directly use the function search() from modules/standard_search.py by importing this file? I've not installed all dependencies so I was not able to try it myself for now.

Edit: After installing it via PIP in python3.6 this works for me:

from google import google
a = google.search('test')
print(a)

Edit2: The requirements are not set correctly for python3 while pip2 installs selenium and unidecode autmatically, it will fail for pip3 if the modules are not installed. I'm going to post a bug report on GitHub

Lukr
  • 659
  • 3
  • 14
  • Yeah. I installed it from pip. How can I use the file from module in the console? – arjun Mar 10 '18 at 15:41
  • I just installed the dependencies in an virtualenv and now I can use the search command. Are you sure you imported it as `from google import google` and not just `import google` ? – Lukr Mar 10 '18 at 15:51
  • I am using pytthon2.7. I followed the Readme. – arjun Mar 10 '18 at 15:54
  • if the import itself don't work can you post the command you used to import and the error message? Probably you have installed the package in the wrong place (pip env not matches your python env) but this typically should raise a `no module named ... ` error not `name ' ' not defined` – Lukr Mar 10 '18 at 15:56
  • I have abandoned that library. It was slowing things. Thanks anyway. – arjun Mar 11 '18 at 07:03