Pycharm ignores new virtual environment after moving existing one or deleting and creating a new one
Asked Answered
M

2

3

If I allow PyCharm to create a virtual environment when creating the project, then delete or move the venv folder, it won't let me select a new one. I can go into the Python Interpreter menu in the settings and select an existing one that I created myself (note /brokenInterpreter/oldFolder/venv vs /brokenInterpreter/venv):

enter image description here

But nothing happens when I hit "Ok" in the "Add Python Interpreter" dialog. It simply ignores what I entered. When I exit out, PyCharm still attempts to use the old, non-existant interpreter.

How can I get around this?


PyCharm version: 2022.2 Build #PY-222.3345.131, built on July 27, 2022 (Professional Edition)

Meshwork answered 8/10, 2022 at 15:31 Comment(1)
M
5

I think this is a bug, but I'll document the fix here.

I had to go into the "Show All" menu, and find the old "[invalid]" entry:

enter image description here

Then once that's removed from the list using the - button, I was able to add the new interpreter.

Meshwork answered 8/10, 2022 at 15:31 Comment(1)
For reference, the files that populate the Interpreters list and the individual project interpreter are shown in this post.Glace
E
2

Although this does not answer the OP, a very similar problem arises in 2023.2.3 (pro) after externally renaming the parent folder of the project (.idea) and the interpreter (.venv).

In this case, the red [invalid] Python 3.10 (<brokeninterpreter>) was still selected in the "Python Interpreter" dialog, but the broken interpreter did not show up in the "Show All" dialog, so there appeared to be no way to remove it (using the UI, at least). Adding a new interpreter had no effect.

Even after manually removing the .idea and .venv folders and creating fresh ones, the problem persisted.

In this case, the only thing that worked for me was "File" > "Invalidate Caches...", then adding the new interpreter after restart.

Erasure answered 23/10, 2023 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.