问题: 刚安装的PyCharm执行代码报“ModuleNotFoundError: No module named XXXX”错

老猿刚安装好PyCharm后,直接新建了一个工程文件并导入了一个已有的爬虫程序文件,该文件原来在Python解释器下能执行,但在PyCharm下执行时报错:
F:学习pythonSRCprojectsvenvScriptspython.exe F:/学习/python/SRC/SayGoodToCsdnByBF.py
Traceback (most recent call last):
File “F:/学习/python/SRC/SayGoodToCsdnByBF.py”, line 5, in
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named ‘bs4’

Process finished with exit code 1

老猿知道肯定是配置的问题,经过测试,发现只要在:File->Settings->Projector:xxxx->Project Interpreter中设置Python解释器为工程解释器就可以,如图:
在这里插入图片描述

上图中蓝色圈标记的按钮为设置按钮。相关内容可参考《第15.1节 PyCharm安装及使用》工程配置调整介绍的相关内容。

老猿Python,跟老猿学Python!
博客地址:https://blog.csdn.net/LaoYuanPython

老猿Python博客文章目录:https://blog.csdn.net/LaoYuanPython/article/details/98245036
请大家多多支持,点赞、评论和加关注!谢谢!

原文地址:https://www.cnblogs.com/LaoYuanPython/p/11931744.html