Can not import module search from google module in python

别来无恙 提交于 2019-12-24 12:56:27

问题


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


回答1:


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')




回答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"




回答3:


The shortest work around for this will be:

from googlesearch import search



回答4:


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



来源:https://stackoverflow.com/questions/44268763/can-not-import-module-search-from-google-module-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!