'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation

后端 未结 7 1473
天命终不由人
天命终不由人 2021-01-01 09:27

I re-installed windows and opened an existing Pycharm project and get the error \'SDK seems invalid\' in Settings > Project Interpreter.

The project interpreter path

7条回答
  •  囚心锁ツ
    2021-01-01 10:12

    Most probably, some path to Python environment that PyCharm tries to use has become invalid somewhere. There are (at least) two primary suspects:

    Path to your virtualenv in PyCharm settings

    PyCharm needs to know the path to your environment to run things in it. So, if that path changed, PyCharm's saved path has become invalid.

    Go to the interpreter settings for your project in File->Settings...->Project interpreter->(Gear icon)->Show all...:

    Then delete and recreate the necessary entries. Or edit them and specify correct paths. E.g. this is what my list looks like after I deleted an Anaconda installation:

    Path in the virtualenv to its base installation

    Since virtualenv is not a full installation, it must have a path to its base installation stored somewhere to be able to use files from there.

    As of this writing, virtualenv (v16.0.0) in Windows is implemented like this:

    • The real python.exe and several other files are copied into the virtualenv's subtree
    • In Lib\orig-prefix.txt, the path to the base installation is stored. It is used to add the base installation's Lib to sys.path via a custom site.py.

    So, if the path in that file becomes invalid, the virtualenv's Python interpreter will be unable to find any standard modules except those few that were copied. Which perfectly fits your symptoms.

提交回复
热议问题