Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我可以在pythonshell中使用请求,但在Django中没有找到模块?_Django_Import_Module_Python Requests - Fatal编程技术网

为什么我可以在pythonshell中使用请求,但在Django中没有找到模块?

为什么我可以在pythonshell中使用请求,但在Django中没有找到模块?,django,import,module,python-requests,Django,Import,Module,Python Requests,我在Django中尝试导入请求时发现错误模块未找到 我无法让python模块请求在Django中工作。我已经在python中使用pip安装了模块,并且可以在python终端中导入 ModuleNotFoundError:没有名为“requests”的模块 如果我在python shell中运行命令: >>> import requests >>> test = requests.get(url="http://192.168.9.186:2480/connec

我在Django中尝试导入请求时发现错误模块未找到

我无法让python模块请求在Django中工作。我已经在python中使用pip安装了模块,并且可以在python终端中导入

ModuleNotFoundError:没有名为“requests”的模块

如果我在python shell中运行命令:

>>> import requests
>>> test = requests.get(url="http://192.168.9.186:2480/connect/test")


我得到了一个htto 204响应,但在django中,我只得到了模块错误

谢谢@h4k或我对Python和django的天真理解,我认为它们使用的是相同的代码库。我跑完之后:

pip install requests

代码运行完毕并解决了错误。感谢您对这位新手的帮助。

您的Django应用程序是否在与shell相同的(虚拟)环境中执行?请切换到您在Django项目中使用的任何虚拟环境,然后运行
pip freeze
-然后发布输出。astroid==2.2.5 colorama==0.4.1 Django==2.1.7 isort==4.3.16 lazy object proxy==1.3.1 mccabe==0.6.1 pyint==2.3.1 pytz==2018.9 six==1.12.0类型化ast==1.3.1 wrapt==1.11。1@H4kor不,shell是基本的Python3.7shell,我运行导入请求,然后执行get,它工作正常。但是,当我在django views.py中使用导入请求时,我会收到一个未解决的导入错误,因为它无法识别请求。正如您对django virtualenv的pip冻结所示,该环境中没有安装请求。在django virtualenv中运行pip安装请求