Forums

ModuleNotFoundError: No module named 'requests'

In my requirements file, I specify a GitHub repo, which, within its own requirements file has:

requests>=2.20.0

...as well as the following in its setup.py file:

install_requires=["requests>=2.20.0"]

Yet, when I try to deploy on pythonanywhere, I get a ModuleNotFoundError: No module named 'requests'

I'm not quite sure what is going on and why pythonanywhere cannot find requests. (?) This was working before, and today when I wanted to deploy on python anywhere, it resulted in this error.

The specific code for the error is as follows:

Preparing metadata (setup.py) ... error error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [10 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/tmp/pip-req-build-jfg4kkzm/setup.py", line 4, in <module> from pymed.version import version File "/tmp/pip-req-build-jfg4kkzm/<my_file>/init.py", line 1, in <module> from .api import PubMed File "/tmp/pip-req-build-jfg4kkzm/<my_file>/api.py", line 2, in <module> import requests ModuleNotFoundError: No module named 'requests' [end of output]

Thanks for the help!

What version of python was it using? How do you deploy? How do you install your requirements?

Figured it out in the end. It was a tricky one. Fault doesn't lie with pythonanywhere.

I was using the pa_autoconfigure_django.py script and that of course has a pip install -r requirements.txt step; one of those requirements is an external github repo, and that repo suddenly started failing to install.

The issue was with that external package. Their setup.py did a faulty thing (See this post, in particular the WARNING about a race condition; that's exactly what was going on https://stackoverflow.com/questions/2058802/how-can-i-get-the-version-defined-in-setup-py-setuptools-in-my-package)

Basically their setup.py was importing the module, which had requests as an import.

I guess the install order of pip install -r requirements.txt is non-deterministic. If it had installed the Django packages first, then requests would have been installed as a dependency, so then installing that third party repo would have succeeded. I might have just gotten lucky all those times before, or something else switched, that now it always wanted to install that github repo first, which meant requests wasn't yet installed.

I ended up forking the external repo and fixing that setup.py bug myself, and now the install on python anywhere works.

Good catch!

Hello! I am trying to use the requests module to access this public sites:

"https://www.google.com/finance/quote/USD-BRL?hl=pt" "https://www.infomoney.com.br/cotacoes/b3/etf/investo-lfts-lfts11/

My script has the lines: import requests from bs4 import BeautifulSoup

But I got the error message: ModuleNotFoundError: No module named 'requests'

My console is bash with python3.6.

Could you help me to solve this?

Thanks a lot!

This help page explains how to install new modules for different Python versions. However, I'd recommend that you use a more recent version of Python if you can, as 3.6 is quite old.

Also: if you're writing scripts to scrape data, please be aware that free accounts have restricted Internet access, so you can only access the sites on this list. Google is on there, so you'll be OK with the request you're doing now, but you might hit issues if you try scraping other sites in the future.