Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cannot be opened when launching PyCharm CE

I just downloaded the PyCharm CE (community edition), but am having trouble opening it. When I launch the program, an error pops up saying:

python cannot be opened because of a problem.

When I click for more details regarding the problem, I get the following:

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  dyld: No shared cache present
Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
  Reason: image not found

I have searched online for similar questions, but not been able to figure out what the problem is. My guess is that it might have something to do with dependency versions or something?

Mac Software: Mac OS Big Sure 11.1

Python Version: Python 3.9.1

I did not have this problem before updating my OS to Big Sur, perhaps this is part of what is causing the problem?

And advice, or links to helpful websites/resources would be greatly appreciated.

Edit: This problem only occurs when I click to start a new project in PyCharm.

I have also tried reinstalling both Python and PyCharm, but this did not work.

Screenshot of error message:

enter image description here

Edit 2:

This is all that shows up when I go into preferences -> python interpreter

enter image description here

And the original paths for creating a new project:

enter image description here

like image 736
Ethan Avatar asked Feb 06 '21 22:02

Ethan


2 Answers

The short answer: upgrading to Big Sur may have broken your old Python installation, but your project in PyCharm is still trying to use it. The fix (on PyCharm 2020.3):

  • Download and install a fresh installation of Python (in my case, Python 3.9)
  • In PyCharm, in your project, go to Preferences... -> Project: YourProject -> Python Interpreter
  • Open the dropdown next to the Python version the project's currently set to, and click "Show All..."
  • Click "+" in the lower left to add a new Python Interpreter / virtual environment
  • In the "Add Python Interpreter" window that opens, open the dropdown next to "Base Interpreter" and select the version of Python you just installed
  • You will also likely need to click the folder icon next to "Location:" and make a new Location that doesn't end in "/venv". (In my case, since I'm using Python 3.9, I made a new folder called "venv_3.9".)

That should fix things for your current project. To fix it for new projects:

  • File -> New Project Settings > Preferences for New Projects...
  • Select Python Interpreter
  • Make sure the Python Interpreter is either "No interpreter" or your newly-installed interpreter.

The Odyssey:

I was using Python 3.5 before the upgrade. My Python Console in PyCharm was showing an error loading a library from

/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

A bit more investigation showed there was no file or directory at that location.

Running

/usr/local/bin/python3

from the Terminal generated the same error: it looks like the upgrade to Big Sur removed one or more libraries the Python 3.5 installation was using.

I closed Terminal. (This step is important because the Python installer will try to update the path information in Terminal, but, unless you want to do some command line magic, Terminal only reads the path when it first starts running.)

Python 3.5 is no longer available for download, so I downloaded Python 3.9.1 and installed it (and ran the command to install the extra certificates -- see the ReadMe file that comes with the installation for details).

Then I launched Terminal again, ran

/usr/local/bin/python3 --version 

(NOT the same as the file at /usr/bin/python3) and

/usr/local/bin/python3.9 --version

and verified that Python 3.9 started and successfully printed its version for both commands. Running "which python3" also confirmed that the installer had updated my path to point to Python 3.9:

$ which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3

At this point, PyCharm was still throwing the "Python cannot be opened" errors.

The next step was to notice that the status bar at the bottom of the open project window still showed "Python 3.5", the broken version.

Either clicking the "Python 3.5" and selecting "Add Interpreter..." or going through "Preferences... -> Project: YourProject -> Python Interpreter" as described above will eventually let you add a new interpreter.

In the "Add Python Interpreter" dialog, I used the dropdown next to "Base Interpreter" to select /usr/local/bin/python3.9 (which was above the entry for python3.5; you may have to scroll up to see it). "OK" was still dimmed until I clicked the folder next to the "Location" entry and made a new folder for the new Python virtual environment. After clicking "OK", the PyCharm errors settled down.

Last step: keep the problem from happening again. According to the Jet Brains Docs, you can set the default Python interpreter by going to File -> New Project Settings > Preferences for New Projects... There, you can select Python Interpreter to see the default interpreter for new projects. The important thing here is to make sure it's not still pointed at a broken interpreter so any new projects you create won't start throwing errors again.

like image 107
jtc Avatar answered Sep 29 '22 08:09

jtc


Big Sur is pretty new, so what you can do is reinstall Python and reinstall PyCharm. This can also be compatibility issues. If nothing works you can file a bug.

like image 40
DARSIN Avatar answered Sep 29 '22 08:09

DARSIN