ModuleNotFoundError:没有名为“请求"的模块,但它已安装? [英] ModuleNotFoundError: No module named 'requests' but it's installed?

查看:20
本文介绍了ModuleNotFoundError:没有名为“请求"的模块,但它已安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CMD 中使用了命令 pip install requests 并成功安装了请求模块,但是当我尝试将其导入 PyCharm 中的文件时,它会抛出

I used the command pip install requests in CMD and successfully installed the requests module, but when I try and import it to my file in PyCharm it throws

"ModuleNotFoundError: 没有名为请求"的模块

"ModuleNotFoundError: No module named 'requests'

我看到了一些关于这个问题的其他帖子,但没有找到可行的解决方案.

I saw a couple other posts about this issue but did not find a working solution.

作为旁注,我已经在我的 Python IDLE 中成功运行了这段代码,所以我认为这不是代码问题,而只是我的 PyCharm 设置的问题.

As a side note I have successfully run this code in my Python IDLE so I presume this is not a code issue, and just an issue with my PyCharm settings.

Traceback (most recent call last):
  File "C:/Users/danie/PycharmProjects/Web_Scraping_Project/Web_Scraper.py", line 1, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Process finished with exit code 1

推荐答案

你必须激活虚拟环境.

source venv/bin/activate
pip install requests

或者您可以从 PyCharm GUI 添加库.有一个+"在编辑解释器的设置中,点击在上面搜索 requests 库.

Or you can add the library, from the PyCharm GUI. There is a "+" on the edit interpreter in settings in the, click on it and search for the requests library.

这篇关于ModuleNotFoundError:没有名为“请求"的模块,但它已安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆