4

I installed the google module by Mario Vilas in my virtual environment in ubuntu 14.04 with python2.7 https://pypi.python.org/pypi/google I have done this before in both windows and Ubuntu and it worked fine. However, now when I do the following

>>> from google import search
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: cannot import name search

I am using pycharm and I can view the package and its modules and I can auto insert using ctrl+space

I tried giving total privileges to the virtual venv package using sudo chmod -R ugo+rX but to no avail

enter image description here

13
  • Do you perhaps have a file named google.py in the current directory? Commented May 30, 2017 at 18:03
  • No, even if I did, the pycharm clicking option should point me to the wrong file. It does not Commented May 30, 2017 at 18:05
  • Check for circular dependancies, in your import statements. Commented May 30, 2017 at 18:06
  • Try this: import google; print google.__file__ to see if you're getting the correct module. Commented May 30, 2017 at 18:06
  • 1
    It sounds like your installation of Python came with a built-in module named google which is taking precedence over the one you installed. Try renaming your installed version to something else and see if you can import it that way. Commented May 30, 2017 at 18:22

6 Answers 6

4

The shortest work around for this will be:

from googlesearch import search
Sign up to request clarification or add additional context in comments.

Comments

3

Your installation of Python came with a built-in module named google which is taking precedence over the one you installed. You have two options:

  1. Remove the built-in module.
  2. Use importlib to import the desired module by its filesystem path:

    google = importlib.import_module('/usr/local/lib/python2.7/site-packages/google/__init__.py')

Comments

2

"from google import search" is giving error as there is no module with the name "google".After "pip install google" i checked the path to find out out the module in lib, but i was not able to find. I checked and found a module with "googlesearch". By doing the below change in my code i was able to solve the issue

OLD : "from google import search" NEW : "from googlesearch import search"

1 Comment

The module has been modified and the issue was resolved already. Your answer adds no value, unfortunately
0

simply install both google and google-search

pip install google pip install google-search

It works for me

Comments

-1

Just import google and you will be all set :)

import google

It is tested and verified.

Comments

-4

I have gone through the same problem and i solve it by importing googlesearch API like this: from googlesearch import *

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.