Invalid Python interpreter selected for the project
Question:
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:UsersakshaPycharmDigital ClockvenvScriptspython.exe" (in directory "C:UsersakshaPycharm60 Python ProjectsDigital Clock"): CreateProcess error=2, The system cannot find the file specified
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.
@thuyein’s answer did work for me. However, you can also find references to VIRTUAL_ENV in: activate.bat, activate.fish, activate.nu. I updated all of those, then updated the path to interpreter in interpreter’s settings as well.
In settings/Project:[your_project_name]/Python Interpreter the gear icon next to Python Interpreter’s path contains ‘Show all’ option. These are all interpreters that Pycharm found on your machine. The paths that got messed up are highlighted in red and marked as [Invalid]. Choose the original path of your project’s interpreter and just update it (there’s an Edit button at the top of the list) – then you’ll be able to set it as current interpreter.
For me, PyCharm did not have permissions to read /usr/local
due to its confinement. I uninstalled it, then installed it as:
sudo snap install pycharm-professional --classic
This gave it the required permissions, following which the interpreter error did not reoccur. Following this, create a launcher entry for it.
For flatpak
, consider this answer.
Steps are as follows.
- Open Pycharm
- On extrem right bottom, click on Python version (for example 3.11)
- Select Interpreter Settings
- A new window will popup where select the project (project:YOUR_PROJECT_NAME)
- From right hand side window select python.exe and click on Ok
it should resolve this issue, I’ve just sorted out following these steps.
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:UsersakshaPycharmDigital ClockvenvScriptspython.exe" (in directory "C:UsersakshaPycharm60 Python ProjectsDigital Clock"): CreateProcess error=2, The system cannot find the file specified
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.
@thuyein’s answer did work for me. However, you can also find references to VIRTUAL_ENV in: activate.bat, activate.fish, activate.nu. I updated all of those, then updated the path to interpreter in interpreter’s settings as well.
In settings/Project:[your_project_name]/Python Interpreter the gear icon next to Python Interpreter’s path contains ‘Show all’ option. These are all interpreters that Pycharm found on your machine. The paths that got messed up are highlighted in red and marked as [Invalid]. Choose the original path of your project’s interpreter and just update it (there’s an Edit button at the top of the list) – then you’ll be able to set it as current interpreter.
For me, PyCharm did not have permissions to read /usr/local
due to its confinement. I uninstalled it, then installed it as:
sudo snap install pycharm-professional --classic
This gave it the required permissions, following which the interpreter error did not reoccur. Following this, create a launcher entry for it.
For flatpak
, consider this answer.
Steps are as follows.
- Open Pycharm
- On extrem right bottom, click on Python version (for example 3.11)
- Select Interpreter Settings
- A new window will popup where select the project (project:YOUR_PROJECT_NAME)
- From right hand side window select python.exe and click on Ok
it should resolve this issue, I’ve just sorted out following these steps.