0
我想讓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'
任何指針,我在做什麼錯在這裏?
謝謝安東尼。是的,我正在使用Windows二進制版本。我會嘗試源代碼版本,但沒有辦法在二進制版本中安裝和導入新模塊? – 2014-10-29 13:56:53
那麼,你可以將模塊複製到「site-packages」目錄中,但是如果你安裝了Python,我認爲沒有任何理由在源代碼版本上使用Windows二進制文件(Windows的目的和Mac二進制文件只是爲沒有安裝Python的系統提供完全自包含的軟件包)。 – Anthony 2014-10-29 19:38:57
明白了。非常感謝! – 2014-10-29 20:25:07