Problem
The PyCharm terminal shows (.venv) in the prompt, but the active virtual environment belongs to another folder, for example to another project. Scripts started from this terminal cannot find the installed packages and fail, for example, with ModuleNotFoundError: No module named .... The same scripts work in a system terminal with the right .venv.
which -a python3 in the PyCharm terminal lists the .venv of the other folder first:
(.venv) user@host:~/projects/project_a/scripts$ which -a python3
/home/user/projects/project_b/.venv/bin/python3
/usr/bin/python3
Settings | Python | Interpreter shows the right .venv. The commands deactivate and source .venv/bin/activate fix the terminal until the project is opened again.
The problem is seen in PyCharm 2026.2.
Cause
In PyCharm 2026.2, the list on the left of Settings | Python | Interpreter shows folders of the project. For example, the list shows the main project folder and subfolders with a pyproject.toml file. Each folder in the list can have a different interpreter. The page shows the interpreter of the selected folder only.
A terminal uses the interpreter of the folder in the list that contains the terminal folder. A subfolder that is not in the list uses the interpreter of the main project folder. So when the main project folder points to the .venv of another folder, the terminal activates that other .venv. The other folders in the list can still show the right one.
The .venv of another project can be in the list of interpreters. PyCharm searches for virtual environments only inside the project folder, in ~/.virtualenvs and in pyenv. It does not select an environment from another project by itself. The list of interpreters is different. It holds every environment PyCharm has registered, from every project. An environment that has no record of the project it belongs to is offered in all projects, so it can be selected for the wrong one.
Resolution
- Open Settings | Python | Interpreter.
- In the list on the left, click the first folder.
- Check the Python Interpreter field. Repeat for every folder in the list.
- If the field shows the
.venvof another folder or project, select the right.venvin Python Interpreter. - Click OK.
- Open a new terminal tab. Terminal tabs that are already open keep the old environment.
- Run
which -a python3. The first line shows the.venvof the project.
The resolution was checked on PyCharm 2026.2.3 (build 262.10968.92) on Linux.
If all folders in the list show the right interpreter and the terminal still activates another .venv, contact PyCharm support. Attach the logs from Help | Collect Logs and Diagnostic Data.
Comments
0 comments
Please sign in to leave a comment.