Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm issue after moving project folder: Cannot setup python SDK at Python 2.7 (/Library/Framework...)

I am running PyCharm Community 2018.2 on macOS 10.13.6

II know that macOS comes with Python preinstalled. I believe that when you go to https://www.python.org/, download the python-3.7.0-macosx10.9.pkg file, and run it to install Python, it installs Python, a second time, but in a different location.

I believe that the location of the pre-installed macOS Python is: usr/bin/python. I know this by opening Terminal and typing which python. I also believe that if I want to see the location that the .pkg file installed Python, I'd need to type in: which python3. When I do that, I get: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.

I created a new Python project a few weeks back that just contains one .py file, and that's it. I did some file clean-up to get better organized, and I moved that project folder into a new folder. Today when I opened PyCharm, I went to Open: and I searched for and selected that project folder and clicked Ok. It loaded, and I could see my python code in the .py file. The 'run' option was grayed out, and I saw the warning message: Invalid python interpreter selected for the project. --- Configure Python interpreter. I clicked to configure the Python interpreter. I had done this once before, but I did not understand it very well then, and I still do not. I see that I can click the sprocket at the end of the line labeled Project interpreter, and select "Add..."

Then I see two main options:

  • New Environment
  • Existing Environment

At this point, I just get really confused.

  • I am in the configuration of the "Project Interpreter."
  • Under New Environment there is an option for a "Base Interpreter."
  • Under Existing Environment, there is also a field that is just labeled "interpreter."
  • To the left there is the option of System Interpreter: and when I select it, I see /usr/local/bin/python3.7

It seems like no matter where I try to find the correct interpreter, I get the same error message: Cannot setup a python SDK at Python 2.7 (Project_Folder) (/Library/Framework.../venv/Scripts/python.exe)

If I select "Existing environment" and navigate to /Library/Frameworks/Python.framework/Versions/3.7/Python... I get the error.

If I select "Existing environment" and navigate to /usr/bin/python... it seems to resolve the issue, and I can run the .py file's code again. But is that not the wrong installation of Python? Is that not using the interpreter that came with macOS? When I go to PyCharm > Preferences, the Project Interpreter is now showing as: Python 2.7 usr/bin/python. That seems incorrect to me.

like image 880
Michael Scott Perkins Avatar asked Sep 06 '25 03:09

Michael Scott Perkins


1 Answers

Delete .idea folder

For New Environment:

  • Select the new Virtualenv folder location and it must be empty
  • Select the installed pythone.exe location in Base Interpreter

For Existing Environment:

  • Select the existing Virtualenv folder location and delete it's contents
  • Select the installed pythone.exe location in Base Interpreter

It's worked for me.

Good details: Here

like image 116
Mat Avatar answered Sep 07 '25 20:09

Mat