Akshay Saambram
Akshay Saambram

Reputation: 350

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

Upvotes: 14

Views: 92779

Answers (6)

Joshua Wolff
Joshua Wolff

Reputation: 3351

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

Upvotes: 1

midLVL-py3Guy
midLVL-py3Guy

Reputation: 21

python interpreter re-link to new py3 install/update

Go to programs on Windows menu, find go to letter P section and find your python3 folder
and right-click on your python3 to get the path copy,
next open > in new window > do this until you get to the full path way to the python3 execute file in the python folder, not the shortcut link folder.

Copy your full path by right-click on python exe and copy path.
Next you will go to the pyCharm > settings > python interpreter > then you will click on existing interpreter option
click on the address bar in the pop box, until you can enter your own address in the top search area, paste your fullpath address to the python exe file in the box and it should populate w/ the file tree showing your execute file. Save. Once you re-install your interpreter you should see your packages on the bottom tab refill.

Upvotes: 1

Sunil Kaler
Sunil Kaler

Reputation: 19

Steps are as follows.

  1. Open Pycharm
  2. On extrem right bottom, click on Python version (for example 3.11)
  3. Select Interpreter Settings
  4. A new window will popup where select the project (project:YOUR_PROJECT_NAME)
  5. 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.

Upvotes: 1

Asclepius
Asclepius

Reputation: 63383

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.

Upvotes: 0

pantomassi
pantomassi

Reputation: 33

@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.

Upvotes: 2

thuyein
thuyein

Reputation: 1792

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.

Upvotes: 12

Related Questions