Forums

google.search('pythonanywhere') AttributeError: module 'google' has no attribute 'search'

Hi all, I'm having a problem with module 'google' running on pythonanywhere console. The module was correctly installed with

$ pip3.5 install --upgrade --user google

But when I attempted to run

import google
google.search('pythonanywhere')

the following Error appeared

AttributeError: module 'google' has no attribute 'search'

However the module 'google' works well on my local system. Please help me out. Thank you.

Nuno

Hi there, have you already found this page? http://help.pythonanywhere.com/pages/InstallingNewModules

If so, my guess would be that you're not using the same python version as you installed the google module for. The default "pip" and "python" is 2.7. Try being explict about which python version you want, eg "pip3.5" or "python3.5".

Thank u Harry! I have already read the link. Actually, i used the pip3.5, and in my opinion, this will install google to py3.5. And when i tried to reinstall google, the system showed requirement already satisfied. And then, i used ipython3.5 console to run the module. So, in my opinon, i runed the codes with the correct version of python3.5. Additionaly, i tried also with python 2.7, did't work either. Could you give me some more help with this? Thanks.

Besides, as i was able to import google correctly, does it mean that the module had been correctly installed?

That's strange. I just tried it myself and it seemed to work OK.

Maybe it's worth trying to uninstall google with "pip3.5 uninstall google" and then try reinstalling it? Or switching to using a virtualenv, in case it's some kind of conflict with an already-installed package?

Thank u Harry. I uninstalled the goolge, using pip3.5 uninstall google.

To double check if the google has really been uninstalled, i ran pip3.5 uninstall again. And the result is

19:45 ~ $ pip3.5 uninstall google
Cannot uninstall requirement google, not installed

But given the uninstallation of google, I still can import google in a ipython3.5 console and get the AttributeError info as following

Python 3.5.2 (default, Jul 17 2016, 00:00:00) 
Type "copyright", "credits" or "license" for more information.
IPython 4.1.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
 %quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
In [1]: import google
In [2]: google.search('hello')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-6f53dfa06da9> in <module>()
----> 1 google.search('hello')
AttributeError: module 'google' has no attribute 'search'enter code here

Isn't it very strange?

What happens if you use regular Python instead of IPython?

Also, can you try using a virtualenv?

Aha. While I was waiting I tried it myself, it looks like it works fine with regular python, but I have the same problem as you when I try and use IPython. That is strange.

It looks like IPython picks up an older, system-wide installation of google, but python picks up the user-installed one:

 $ python3.5 -c"import google; print(google.__path__)"
['/home/myusername/.virtualenvs/tmp-94b02590f9d9dc29/lib/python3.5/site-packages/google']

 $ ipython3.5 -c"import google; print(google.__path__)"
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
['/usr/local/lib/python3.5/dist-packages/google']

Hi Harry, i tried the python, the also doesn't work. Now i'm gonna try virtualenv. Thank u.

Hi Harry, it looks like that my python3.5 console also picks up the older system wide installation of google.

Python 3.5.2 (default, Jul 17 2016, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import google
>>> print(google.__path__)
['/usr/local/lib/python3.5/dist-packages/google']

Hi Harry, as instructed by u, i have created a virtualenv named myproject. It looks like that a new installation has been made under the path of myproject, because when i tried to reinstall google, i got the following

Requirement already satisfied: google in ./.virtualenvs/myproject/lib/python3.5/site-packages
Requirement already satisfied: beautifulsoup4 in ./.virtualenvs/myproject/lib/python3.5/site-packages (from google)

Now how could I open a console py3.5 within the virtualenv myproject? Or i can only use it in Django Webapp? Thanks u for your attention.

Virtualenvs aren't just for web apps, no. You can use them from the Bash console any time. There's some details here: http://help.pythonanywhere.com/pages/Virtualenvs

Hi Harry, thank u very much. Finally, i can now use Bash console to run google.searche() correctly. And one more question. Could u please tell me how to save the code lines in the Bash Console? If i could save it, then the next time when i need them, i'll just reload them again. Thanks!

Hi there,

There's no way to save lines of code in a Bash console directly, but if you type the command "history", then you can copy and paste them into a script maybe?

Hi Harry, thank u! At least now i can use the package. I hope someday, pythonanywhere can upgrade the system pacakage of google, then i'll be able to run it with a normal ipython.