web2py"无法导入请求"即使安装了请求

时间:2014-10-29 02:30:19

标签: python python-requests web2py

我正在尝试运行web2py应用程序,并且我在其中一个控制器中有以下代码。

文件名:default.py

import requests

def index():
...

在我目前激活的virtualenv中,我已经使用pip安装了请求,如下所示。

(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...

如果我打开一个python shell,我可以导入请求并执行通常的操作。

(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
>>>

当我尝试访问我的web2py应用程序时,它仍会抛出以下错误。

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'

关于我在这里做错了什么的指示?

1 个答案:

答案 0 :(得分:1)

您很可能正在使用Windows二进制版本的web2py。此版本包含自己的Python解释器,因此它不使用您在计算机(或其任何库)上安装的Python版本。只要安装了Python,最好运行web2py的source code版本。从源代码运行,您将能够导入任何已安装的模块。