Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Python interpreter selected for the project

I use Pycharm, and whenever I move a project to another folder, it says "invalid python interpreter selected for the project". I think it happens because the path to venv has changed.

I tried Configure Python Interpreter > Add Interpreter > Select "Existing Environment" with the new path to venv. I was expecting this to work, but after I click OK, it says "Updating interpreter path" for a moment, and nothing changes. I tried even checking "make available to all projects".

I also tried some of stack overflow answers, but couldn't make it. How can I fix this?

Error:Cannot run program "C:\Users\aksha\Pycharm\Digital Clock\venv\Scripts\python.exe" (in directory "C:\Users\aksha\Pycharm\60 Python Projects\Digital Clock"): CreateProcess error=2, The system cannot find the file specified
like image 413
Akshay Saambram Avatar asked Jan 26 '26 15:01

Akshay Saambram


2 Answers

Virtualenv has hardcoded path inside the bin/activate file, which will fail when you move the virtualenv.

One way is to recreate your virtualenv. Another way is to open the file bin/activate and find this line VIRTUAL_ENV='/private/tmp/test2/.venv' and replace it with your new virtualenv path.

My virtualenv is created at /tmp/test2/.venv for reference.

like image 125
thuyein Avatar answered Jan 28 '26 05:01

thuyein


One thing that worked for me. This issue appeared after I moved project directories. My best guess as to why this works is that PyCharm is copying invalid interpreters when creating a new interpreter. This stops that process.

Click the Python interpreter on the bottom right.

Language button in bottom right

Click the Interpreter Settings.

Interpreter Settings button

Click the arrow next to the current interpreter and click Show All.

Show All button beneath the down arrow

Remove all Invalid Interpreters (highlighted in red).

Remove/minus button

Recreate the virtual environment via "Add Interpreter" and install necessary packages.

Add Interpreter button

like image 29
Joshua Wolff Avatar answered Jan 28 '26 06:01

Joshua Wolff