close

[Solved] ‘Cannot setup a Python SDK’ in PyCharm project using virtualenv after OS reinstallation

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ‘Cannot setup a Python SDK’ in PyCharm project using virtualenv after OS reinstallation in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ‘Cannot setup a Python SDK’ in PyCharm project using virtualenv after OS reinstallation Error Occurs?

Today I get the following error ‘Cannot setup a Python SDK’ in PyCharm project using virtualenv after OS reinstallation in python.

How To Solve ‘Cannot setup a Python SDK’ in PyCharm project using virtualenv after OS reinstallation Error ?

  1. How To Solve 'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation Error ?

    To Solve 'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation Error Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.

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

    To Solve 'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation Error Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.

Solution 1

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.

Solution 2

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.

enter image description here

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read