Rajesh Chamarthi
Rajesh Chamarthi

Reputation: 18818

web2py "unable to import requests" even though requests is installed

I am trying to get a web2py application running and I have the following code in one of the controllers.

file name : default.py

import requests

def index():
...

In my currently activated virtualenv, I have installed requests using pip, as you can see below.

(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in c:\users\rajesh\desktop\code\realpython-part2\web2py\web2pyenv\lib\site-packages
Cleaning up...

If I open up a python shell, I can import requests and do the usual stuff.

(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> python
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://google.com").status_code
200
>>>

When I try accessing my web2py application, it still throws the following error.

Traceback (most recent call last):
  File "gluon/restricted.py", line 224, in restricted
  File "C:/Users/rajesh/Desktop/code/RealPython-Part2/web2py/start/applications/pulse/controllers/default.py", line 1, in <module>
    import requests
  File "gluon/custom_import.py", line 86, in custom_importer
ImportError: Cannot import module 'requests'

Any pointers on what I am doing wrong here?

Upvotes: 0

Views: 1416

Answers (1)

Anthony
Anthony

Reputation: 25536

Most likely you are using the Windows binary version of web2py. This version includes its own Python interpreter, so it doesn't use the Python version you have installed on your machine (or any of its libraries). As long as you have Python installed, you are better off running the source code version of web2py. Running from source, you will be able to import any installed modules.

Upvotes: 1

Related Questions