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

后端 未结 7 1474
天命终不由人
天命终不由人 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 09:51

    I currently have the same issue, that I can't install any package tool in Pycharm and that freak me out. Here is the step I fixed it, just want to share. OuO.

    Step 1

    Find show all in the right corner of a setting icon  Find show all in the right corner of a setting icon

    Step 2

    Click the + icon to open Add python Interpreter  Click the + icon to open Add python Interpreter

    Step 3

    In New environment 's Location Under Virtualenv Environment select file  In New environment 's Location Under Virtualenv Environment select file

    Step 4

    Find your Pycharm file and make an empty file under it and click OK and keep click OK  Find your Pycharm file and make an empty file under it and click OK and keep click OK

    Step 5

    Now in Project Interpreter select the empty file you just create and now you should be fine to install Pycharm package.Hope this solve your problem.  Now in Project Interpreter select the empty file you just create and now you should be fine to install Pycharm package.Hope this solve your problem.

    0 讨论(0)
  • 2021-01-01 09:52

    Here's what solved my problem when I faced the exact same issue

    Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.

    Click show all, if you see the previous existence from the same directory delete that. Click on add or + sign to add a new interpreter and navigate to your project path, navigate down to the virtual environment directory.

    venv/bin/{select the python executable with the version code i.e if you are using python3.6 select python3.6}

    Once selected, you can now click the notice that says install packaging tools, hit apply and done.

    0 讨论(0)
  • 2021-01-01 09:55

    I faced this issue when I switched my system which had different python version installed at different location. The simple short solution is to open 'pyenv' file and point it to the current installation path in your current system and that's it.

    0 讨论(0)
  • 2021-01-01 10:01

    Well, i'm pritty new to Python, and I did too had a re-install of my os after a crash

    Old setup: In the old system setup I used python 3.7.4. I made al my (practice)projects with that, and each project had a venv/scripts/python3.7.exe in it.... my undertanding is/was that all the files in these virtual environment where 'stand alone', so sufficient to run a python 3.7.4 for that specific projec files, and not depending on files of the home-python-dir. The install-directory of python was c:\Program Files (x86)\python 37-32

    Each project had a file [project-path]/venv/pyvenv.cfg, and in this file there was the line home = C:\Program Files (x86)\Python37-32

    then - my system crashed - reinstalled windows 10, and downloaded again python, but this time python 3.8, and it installed in C:\Program Files (x86)\Python38-32

    New setup: So, after some hairs lost - I also installed the old python version 3.7.4 in the specific path stated in the pyenv.cfg file (C:\Program Files (x86)\Python37-32). So, i had 2 python versions installed on my new system, one in .../python38-32 and one in .../python37-32

    And that worked, so when I selected in 'add interpreter/existing interpreter' and pointed to the [project]/venv/python3.7.exe it worked like a charm.

    So, apearantly there are files in each version-specific home-directory that pycharm/python needs - i was under the impression that the files in the .venv directory would be all it needed....

    0 讨论(0)
  • 2021-01-01 10:12

    What solution is: Check out venv\pyvenv.cfg and provide a valid path to the basic python installation.

    What has most probably happend: After reinstalling your OS, you have no base python interpreter reinstalled or you have installed it at different location than before. Thus your virtual environment fails to locate the python installation. Virtual environment implies that all libraries and settings are isolated from other projects. It does not provide an isolated python installation. You still need your base python that had been used for venv creation.

    My case: I have a project in a network share and try accessing it from different computers. The base python paths depend on the very PC. The solution above works fine for me. Unfortunatelly, I need to update pyvenv.cfg depending on the PC in use.

    P.S. I believe that there is an environment variable to overide the venv config value. I only tried to set PYTHONPATH=C:\Anaconda3\envs\python37 on Windows and then to activate venv. It did no effect and I gave it up.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题