Results 1 to 7 of 7

Thread: Python 3 and google library problem

  1. #1
    Join Date
    Dec 2009
    Beans
    554

    Python 3 and google library problem

    Hi,
    I'm using ubuntu mate 16.04 LTS with python v3.5.2 and I installed google library https://pypi.python.org/pypi/google/2.0.1 via pip install google.
    My problem is that with a very simple code taken from https://breakingcode.wordpress.com/2...search-python/
    Code:
    # Get the first 20 hits for: "Breaking Code" WordPress blog
    from googlesearch import search
    for url in search('"Breaking Code" WordPress blog', stop=20):
        print(url)
    I get
    Code:
    Traceback (most recent call last):
      File "dummy.py", line 2, in <module>
        from googlesearch import search
    ImportError: cannot import name 'search'
    The same code works well with python v.2.7.12. Is there any way to use it with python v3.5?
    Thank you

  2. #2
    Join Date
    Jan 2017
    Beans
    235

    Re: Python 3 and google library problem

    pip3 install google

    You need to have the package python3-pip installed https://packages.ubuntu.com/xenial/python3-pip

  3. #3
    Join Date
    Dec 2009
    Beans
    554

    Re: Python 3 and google library problem

    Quote Originally Posted by norobro View Post
    pip3 install google

    You need to have the package python3-pip installed https://packages.ubuntu.com/xenial/python3-pip
    Hi,
    of course I'm already using pip3 (pip calls pip3 as default pip 9.0.1 from /home/user/.local/lib/python3.5/site-packages (python 3.5)).
    Code:
    sudo apt-get install python3-pip
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    python3-pip is already the newest version (8.1.1-2ubuntu0.4).
    0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Python 3 and google library problem

    The recipe described above works perfectly for me on debian jesse. I'll try later on Ubuntu 16.04.
    Code:
    $ sudo apt-get install python3-pip
    $ sudo pip3 install google
    $ cat ./gsearch.py 
    #!/usr/bin/env python3
    
    from googlesearch import search
    for url in search('"Breaking Code" WordPress blog', stop=20):
        print(url)
    $ ./gsearch.py 
    https://wordpress.org/support/topic-tag/breaking-code/
    https://en.forums.wordpress.com/tags/breaking-code
    https://en.forums.wordpress.com/topic/wordpress-breaking-my-embeded-html-code-why
    https://breakingcode.wordpress.com/
    https://breakingcode.wordpress.com/2010/06/
    https://synsinger.wordpress.com/2015/04/14/breaking-code-again/
    https://github.com/mAAdhaTTah/wordpress-github-sync/issues/126
    https://meta.trac.wordpress.org/ticket/1428
    https://blog.resellerclub.com/make-the-most-of-your-wordpress-theme-by-cleaning-house/
    https://www.blogherald.com/2007/07/16/writing-and-publishing-code-in-your-wordpress-blog-posts/
    https://www.kevinmuldoon.com/break-out-frames-javascript/
    https://make.wordpress.org/core/page/2/
    https://wstuartdhij.wordpress.com/2014/09/24/wordpress-blog-tutorial/
    https://trwpconnect.wordpress.com/2016/04/17/welcome-to-make-cycle-4-making-the-code/
    http://jcimoch.github.io/all-tags
    https://ubuntuforums.org/showthread.php?t=2384553
    https://moninagracevilla.wordpress.com/2014/02/21/on-breaking-code-and-pushing-buttons/
    https://blog.puzzlenation.com/2017/10/26/unsung-tales-of-women-in-american-code-breaking/
    $

  5. #5
    Join Date
    Jan 2017
    Beans
    235

    Re: Python 3 and google library problem

    Works for me in 17.10 too.

    As a matter of fact, I can produce the error in python2 because the google package isn't installed:
    Code:
    $ python search.py  
    Traceback (most recent call last):
      File "search.py", line 2, in <module>
        from googlesearch import search
    ImportError: No module named googlesearch
    
    $ python3 search.py  
    https://wordpress.org/support/topic-tag/breaking-code/
    https://breakingcode.wordpress.com/
    ...
    @erotavlas - Check if the google package is installed:
    Code:
    $ ls -nl /home/user/.local/lib/python3.6/site-packages/
    total 16
    drwxrwxr-x 2 1000 1000 4096 Feb  8 11:43 beautifulsoup4-4.6.0.dist-info
    drwxrwxr-x 5 1000 1000 4096 Feb  8 11:43 bs4
    drwxrwxr-x 2 1000 1000 4096 Feb  8 11:43 google-2.0.1.dist-info
    drwxrwxr-x 3 1000 1000 4096 Feb  8 11:43 googlesearch

  6. #6
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Python 3 and google library problem

    Quote Originally Posted by spjackson View Post
    The recipe described above works perfectly for me on debian jesse. I'll try later on Ubuntu 16.04.
    Yes, the same commands work just the same on Ubuntu 16.04. The default python on a fresh Ubuntu 16.04.3 desktop install is python 2.7.

  7. #7
    Join Date
    Dec 2009
    Beans
    554

    Re: Python 3 and google library problem

    Quote Originally Posted by norobro View Post
    Works for me in 17.10 too.

    As a matter of fact, I can produce the error in python2 because the google package isn't installed:
    Code:
    $ python search.py  
    Traceback (most recent call last):
      File "search.py", line 2, in <module>
        from googlesearch import search
    ImportError: No module named googlesearch
    
    $ python3 search.py  
    https://wordpress.org/support/topic-tag/breaking-code/
    https://breakingcode.wordpress.com/
    ...
    @erotavlas - Check if the google package is installed:
    Code:
    $ ls -nl /home/user/.local/lib/python3.6/site-packages/
    total 16
    drwxrwxr-x 2 1000 1000 4096 Feb  8 11:43 beautifulsoup4-4.6.0.dist-info
    drwxrwxr-x 5 1000 1000 4096 Feb  8 11:43 bs4
    drwxrwxr-x 2 1000 1000 4096 Feb  8 11:43 google-2.0.1.dist-info
    drwxrwxr-x 3 1000 1000 4096 Feb  8 11:43 googlesearch
    Hi,
    for me
    Code:
    ls -nl /home/user/.local/lib/python3.6/site-packages/
    ls: cannot access '/home/user/.local/lib/python3.6/site-packages/': No such file or directory
    Code:
    pip --version
    pip 9.0.1 from /home/user/.local/lib/python3.5/site-packages (python 3.5)
    Code:
    pip list | grep google
    DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the 
    [list] section) to disable this warning.
    google (2.0.1)
    google-api-python-client (1.6.5)
    google-search (1.0.2)
    search-google (1.2.1)
    Adding this code
    Code:
    import googlesearch
    print (googlesearch.__file__)
    gave me:
    Code:
    /home/user/miniconda3/lib/python3.5/site-packages/googlesearch/__init__.py
    Quote Originally Posted by spjackson View Post
    Yes, the same commands work just the same on Ubuntu 16.04. The default python on a fresh Ubuntu 16.04.3 desktop install is python 2.7.
    Hi,
    I just tried with a fresh install of ubuntu 16.04 and it works.
    Last edited by erotavlas; February 14th, 2018 at 06:18 PM. Reason: Correct a link

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •