Home > Software design >  'Invalid Python SDK' error right after creating a new project in PyCharm
'Invalid Python SDK' error right after creating a new project in PyCharm

Time:10-24

Background

Some time ago I seriously crashed my Windows computer while using PyCharm - I remember some errors about memory and then a hard crash with no blue screen - just black with some thin vertical lines and reboot to Windows installation / fixing screen. Since then, I had this problem, with no way I found online to fix this.

The problem

Whenever I open a project, or create a new one, an error appears with the Invalid Python SDK error message.


**Invalid Python SDK**
Cannot set up a Python SDKat Python 3.9 (%projectName%) (%projectPath%).The SDK seems to be invalid.

Also, this is what the work environment looks like the moment I close this message. In the Project window, the venv directory (and every directory under it) is marked as an Exclusion, and in the code, the print(f'Hi, {name}') function is marked as an unresolved reference error shown below. The program, however, executes flawlessly.

unresolved reference error

What's more, when I go to Python Interpreter settings at File -> Settings -> Project -> Python Interpreter there's a yellow bar on the bottom which says:

Non-zero exit code (4).

which after some time says:

Python packaging tools not found.

Upon installing, nothing changes, and I can't add packages from this screen (the ' ' button is greyed out):

greyed out

When I try to check Python interpreter paths, there are no paths shown, and I don't know what that means:

no paths

In short, all of the default Python functions like print are marked as errors, even though they work when executed. This makes coding extremely confusing, as I can't quickly distinguish between real errors and 'errors'.

The search for solution

Normally this would be a problem with interpreter set-up or path, but I've tried most of the methods proposed in other answers to similar questions. To name a few :

  • PyCharm shows unresolved references error for valid code
  • 'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation
  • Why do I get an 'SDK seems invalid' error when setting up my Project Interpreter in PyCharm?
  • Invalid Python SDK Error while using python 3.4 on PyCharm
  • Invalid Python SDK when setting a venv There were supposed to be links, but I don't have enough reputation on Stack Overflow to post them with the questions. These, however, can be easily looked up in Google, all of them are posted to Stack Overflow.

What I tried

I should mention that the first things I tried were removing and installing PyCharm, all user configurations and Python itself as well. I installed Python from the official site, and from the PyCharm application, both methods ended with the same result.

  1. File -> Invalidate Caches... -> Invalidate and restart. Didn't work.
  2. Checking file interpreter in Edit Configurations. Don't know what to make of it. The result:

The result.

  1. Refreshing the interpreter paths. Even now, the paths yield no results.

no results

  1. Removing the interpreter and adding it again. No result.
  2. Deleting the .idea folder. No result.
  3. Deleting PyCharm user preferences under %homepath%/.PyCharm50. I don't have that folder though.
  4. Switching interpreter back and forth. No result.
  5. Creating a new interpreter in a different location. No result.
  6. Marking project directory as root ProjectName -> Mark Directory as -> Sources Root and unmarking other directories as Excluded. No result.
  7. Using no interpreter. Yeah, it doesn't mark non-errors as errors anymore. But the code doesn't work. That's not a solution for me.
  8. Checking if venv/pyvenv.cfg has paths set correctly. These look fine to me.

fine

  1. Checking Windows environment variables - Path variable. It was in the user section, but wasn't in the system section. I added it, restarted but still no result.
  2. Changing account name in Windows. My account name was 'username' and that's how my User folder is called `C:\Users\username', but I later connected it to Microsoft account and my user name is now User Name with a space and I can't really change it. My folder stayed the same. Not sure if I can fix it that way.

To the two last things I tried I should also add that I changed my Windows username from 'username' to 'user name' with a space, but that wasn't until recently.

I'm attaching the idea.log file for you to check. I replaced my real username with 'User Name' to highlight the existence of a space.

CodePudding user response:

OK, that was a lucky one! I'm thus posting my comment as an answer:

The problem is caused by the non-ASCII characters in the path, and the solution is to remove them. As indicated by @TheLazyScripter this is a known issue.

  • Related