Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.6 import requests

Hi im pretty new to python and im following some tutorials online. im using the latest version of python 3.6 when i try and import requests or bs4 is says

ModuleNotFoundError, No module named 'requests'

although it is installed i can see it in site packages i used pip to install whatever i seem to do it doesnt seem to be able to find it

here is the code

import requests
from bs4 import BeautifulSoup
import operator


def start(url):
    word_list = []
    source_code = requests.get(url).text
    soup = BeautifulSoup(source_code)
    for post_text in soup.findAll('div'):
        content = post_text.string
        words = content.lower().split()
        for each_word in words:
            print(each_word)
            word_list.append(each_word)

start('http://localhost/budget_app/dashboard.php')

this is the error

ModuleNotFoundError, No module named 'requests'
like image 995
Avi Teller Avatar asked May 01 '17 22:05

Avi Teller


People also ask

Is requests included in Python 3?

The Requests library is available for both Python 2 and Python 3 from the Python Package Index (PyPI), and has the following features: Allows you to send HTTP/1.1 PUT, DELETE, HEAD, GET and OPTIONS requests with ease.

Why is import requests not working in Python?

The Python error "ModuleNotFoundError: No module named 'requests'" occurs for multiple reasons: Not having the requests package installed by running pip install requests . Installing the package in a different Python version than the one you're using. Installing the package globally and not in your virtual environment.

What is Python import requests?

Definition and Usage. The requests module allows you to send HTTP requests using Python. The HTTP request returns a Response Object with all the response data (content, encoding, status, etc).

Do you need to import requests in python?

If you are using the requests module, then that's the only thing you need to import. The rest is taken care of for you by Python. That urllib3 is used by requests is an implementation detail, unless you need to access specific objects defined by the urllib3 library you don't need to import that into your codebase.


1 Answers

Run following command on your virtual environment:

sudo pip install requests
like image 151
Rahul Bagal Avatar answered Nov 08 '22 16:11

Rahul Bagal