已經(jīng)安裝了 pytest
庫(kù)茉盏,在 PyCharm 里的 python 文件中 import pytest
卻依舊報(bào)錯(cuò)混滔,報(bào)錯(cuò)如下:
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:你的項(xiàng)目名 -> Python Interpreter
包列表中有顯示 pytest
呀,頓時(shí)懵逼了征冷!
Python Interpreter包列表.jpg
然后我發(fā)現(xiàn) Python Interpreter
下拉框有多個(gè)Python解釋器路徑择膝,然后我一個(gè)個(gè)把庫(kù)都安裝上就好了,O(∩_∩)O哈哈~
Python Interpreter下拉框.png
總結(jié):
可能是因?yàn)榄h(huán)境匹配問(wèn)題资盅,本地裝的和 PyCharm 使用的庫(kù)地址不一樣導(dǎo)致的