pythonpippycharmpython-venv

Python Virtual Environment Error Configuring SDK in PyCharm


I'm trying to create a Python virtual environment in PyCharm but keep getting this error:

Error Configuring SDK

Error configuring SDK: No flavor detected for B:/myproject/.venv/Scripts/python.exe sdk. Please make sure that B:\myproject\.venv\Scripts\python.exe is a valid home path for this SDK type.

However, it appears that the environment is created just fine. I can activate it from a terminal and install packages. Yet PyCharm refuses to add it, so something is wrong.

When creating the environment, PyCharm has three base interpreter options (3.11 and 3.12, and a 3.12 install in %localappdata%\Microsoft\). I'm using the default option at %localappdata%\Programs\Python\Python312\python.exe. This is the one used by py in terminal. However, when I run py --version inside the virtual environment, I get 3.11.3. Outside it I get 3.12.0.

This has worked fine plenty of times before, and I have no idea what changed.


Solution

  • For anyone with a similar issue: I think this is a problem with virtualenv creating virtual environments on a network share.

    I'm having similar issues on Windows and Ubuntu with PyCharm and VS Code. python3 -m venv venv works just fine, but virtualenv (used by PyCharm) seems to consistently run into problems.

    The best workaround I've found is to stop putting virtual environments inside my project directories (which are stored on a NAS). Instead I put the virtual environments in my home directory on the local disc.

    Of course, this doesn't solve the underlying issue that I can't create virtual environments on a network share.1 This has worked a hundred times in the past, and I can't figure out why it suddenly broke on multiple machines.


    1 Yes, I'm aware that virtual environments should only be used on the machine that created them, which is what I do. But storing them on a mounted network drive makes perfect sense when (a) you want to keep your venv with the code, and (b) your NAS has both redundancy and way more storage space than C:\.