No module named 'pytest' within PyCharm; works in Python CLI.
PyCharm 2022.2.1
Python3.9
Debian 9 latest (12/9/2022)
PyTest 6.0.2-2
Did an upgrade from 2021-something to 2022.2.1 and when doing a Python Test from 'Run/Debug Configuration', the line 5 (of my test code) doing:
import pytest
fails with
Testing started at 1:16 PM ...
Traceback (most recent call last):
File "/opt/pycharm/pycharm-community-2022.3/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py", line 5, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
* WORKAROUND *
Go to 'Settings -> Tools -> Python Integrated Tools' and scroll down to where it says `pytest not found` and there is a `FIX` button.
Clicking on that and viola, happy as a clam.
请先登录再写评论。
This is crazy. Why would a fix be buried in the Settings, instead of either automatically fixing it, or asking when the error is first encountered?
Hello,
>instead of either automatically fixing it,
The package installation cannot be automatically launched as this is not save from the security reasons. It is assumed that the python environment is being configured by the user according to the requirements.
The package is also can be installed in https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html or quick fix in the editor :
today i hit the same problem. the “workaround” worked.
But my question is: why this happens? Yesterday and the days before all was working within IDE and console. today i hit this problem while tests still work in terminal (within IDE and venv enabled)
moritz loeser My best guess is that you use different environments between PyCharm and the terminal. Maybe a different interpreter is selected for a particular run/debug configuration?
the “venv” in console of IntelliJ was at least the day before the same and everything worked. I set venv on first day of project to venv folder in project. and on the day of error it was still same - worked in console of intellij and in console of OS.
But the little green play button stopped working. So if intellij had an different venv then for some odd reason it decided to change it.