PyCharm 报错 ModuleNotFoundError:
2021-07-29 本文已影响0人
神梦无痕
已经安装了 pytest 库,在 PyCharm 里的 python 文件中 import pytest 却依旧报错,报错如下:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py", line 1, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
ModuleNotFoundError.jpg
在 PyCharm 中 Settings -> Project:你的项目名 -> Python Interpreter 包列表中有显示 pytest 呀,顿时懵逼了!
Python Interpreter包列表.jpg
然后我发现 Python Interpreter 下拉框有多个Python解释器路径,然后我一个个把库都安装上就好了,O(∩_∩)O哈哈~
Python Interpreter下拉框.png
总结:
可能是因为环境匹配问题,本地装的和 PyCharm 使用的库地址不一样导致的