在虚拟环境python 2.7 pycharm中安装后无法导入请求

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在虚拟环境python 2.7 pycharm中安装后无法导入请求相关的知识,希望对你有一定的参考价值。

所以我导航到我的虚拟环境。

激活它

pip install requests

它安装

我去了一个文件然后import requests

然后得到这个错误:

No module named request less... (Ctrl+F1) 
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.

我再次做pip安装只是为了看到我得到这个:

pip install requests
Requirement already satisfied: requests in ./lib/python2.7/site-packages
Requirement already satisfied: certifi>=2017.4.17 in ./lib/python2.7/site-packages (from requests)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./lib/python2.7/site-packages (from requests)
Requirement already satisfied: idna<2.7,>=2.5 in ./lib/python2.7/site-packages (from requests)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in ./lib/python2.7/site-packages (from requests)

我正在使用pycharm并在django项目中。我不认为这些问题只是为了以防万一。

答案

答案是我的pycharm软件设置为python的全局安装,而不是我的虚拟环境实例。我必须按照以下说明设置pycharm以使用该env实例:

http://exponential.io/blog/2015/02/10/configure-pycharm-to-use-virtualenv/

以上是关于在虚拟环境python 2.7 pycharm中安装后无法导入请求的主要内容,如果未能解决你的问题,请参考以下文章

在python 2.7中安装openpyxl

Python库的优雅安装及PyCharm虚拟环境配置

在conda虚拟环境中安装OpenCv并在pycharm中使用

在window的cmd中安裝virtualenv和在pycharm安裝virtualenv

python 2.7 - 3.5 升级之路 : 准备阶段开发环境 -- pip3, vitualEnv, pycharm

windows下的pycharm配置 linux环境