2

I have been trying to figure out this problem for few weeks now, but am still stuck. I have been researching it and slowly getting more information but have not been able to solve it yet.

I have read these similar questions on Stack Overflow:

dyld: Library not loaded: /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Python

dyld: Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

Resolving PyCharm python error - dyld: Library not loaded

The problem is that every time I launch PyCharm, the error below pops up:

Process:               Python [15298]
Path:                  /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.6.4 (3.6.4)
Code Type:             X86-64 (Native)
Parent Process:        pycharm [14715]
Responsible:           pycharm [14715]
User ID:               501

Date/Time:             2021-03-27 08:19:23.857 -0700
OS Version:            macOS 11.2.3 (20D91)
Report Version:        12
Bridge OS Version:     3.0 (14Y908)
Anonymous UUID:        130B1388-444D-6CF3-9D98-7F06C81783B0

Sleep/Wake UUID:       89450DAE-41C7-4035-B0DA-8AAB177D9DD3

Time Awake Since Boot: 82000 seconds
Time Since Wake:       1000 seconds

System Integrity Protection: enabled

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

Binary Images:
       0x100000000 -        0x100000fff +org.python.python (3.6.4 - 3.6.4) <E585A67D-C0DB-448A-2E74-422D61BDC1C1> /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
    0x7fff639aa000 -     0x7fff63a45fff  dyld (832.7.3) <0D4EA85F-7E30-338B-9215-314A5A5539B6> /usr/lib/dyld

Model: MacBookPro14,2, BootROM 429.80.1.0.0, 2 processors, Dual-Core Intel Core i5, 3.1 GHz, 8 GB, SMC 2.44f6
Graphics: kHW_IntelIrisGraphics650Item, Intel Iris Plus Graphics 650, spdisplays_builtin
Memory Module: BANK 0/DIMM0, 4 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C3531324D3332443250462D3039
Memory Module: BANK 1/DIMM0, 4 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C3531324D3332443250462D3039
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x171), Broadcom BCM43xx 1.0 (7.77.111.1 AirPortDriverBrcmNIC-1675.1)
Bluetooth: Version 8.0.3d9, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB 3.0 Bus
USB Device: Apple T1 Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.4
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.4

I believe that this started to occur after updating either my PyCharm installation, Python, or my Xcode Developer tools. From my research, I have concluded that a few possible issues might be causing this to occur.

  1. Something might be broken with my Virtual Environments

  2. Something might be broken with my PATH

  3. Something might be broken trying to manage multiple Python versions on my computer

Some more information about my situation.

At the top of the PyCharm error message it shows the line:

Path:/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python 

This seems to suggest that PyCharm might be trying to launch with Python 3.6?

When I type the env command in terminal I get the following output:

PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions
 /3.9/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/
Versions/3.9/bin:/Users/my_name/opt/anaconda3/bin:/Users/my_name/opt/anaconda3/condabin:/anaconda3/bin:
 /Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/
bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/
bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin

A few of the solutions mentioned in previous questions involve either changing the PATH or deleting/recreating the virtual environment.

I am really not familiar with how to do either of these things. Does anyone have any insight on what I can do to stop this error message from popping up every time I launch PyCharm? I am a novice when it comes to Terminal so I am not sure I understand the previous solutions.

Does anyone have any ideas what the problem might be or what I might be able to do to fix this? I have tried reinstalling both Python and PyCharm and neither of these solutions fixed the problem.

Note, I am running:
Max OS: Big Sur 11.2.3
Python 3.9
PyCharm: Community 2020.3.4
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Ethan
  • 876
  • 8
  • 18
  • 34
  • 1
    can u try: `PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin" && export PATH` in your terminal, and then open pycharm? – marcos Mar 27 '21 at 05:10
  • 1
    I hope you understand that whatever the solution for this is, you have to learn how to create a venv and how to update PATH. It's relatively easy and without those 2 steps you won't be able to solve the majority of problems you're certain to run into. – bad_coder Mar 27 '21 at 09:39
  • @Marcos unfortunately, this did not solve the problem. – Ethan Mar 27 '21 at 15:06
  • @bad_coder I appreciate the insight - I will keep reading resources to learn more about these. – Ethan Mar 27 '21 at 15:08
  • 2
    @Ethan for the venv using the [PyCharm GUI](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html) is really easy, it's fast to understand (also look at [PyPI](https://pypi.org/)). Afterwards it's good taking a few more minutes to learn [how to do it manually](https://docs.python.org/3/library/venv.html). [The PATH](https://docs.python.org/3/tutorial/modules.html#the-module-search-path) is perhaps more complicated, learn about how to set you OS environment variables (that's about it, 2 or 3 hours). Multiple Python versions should boil down to the former. – bad_coder Mar 27 '21 at 15:15
  • 1
    Try creating a new venv with the GUI (first link in the previous comment). If all goes well you'll get this running in a few minutes. – bad_coder Mar 27 '21 at 15:18
  • @bad_coder thank you for linking to these resources! Pretty crazy - I just reset the default settings for PyCharm and it seemed to resolve the problem. (Might have fixed whatever I had wrong with the PATH). I really appreciate your help though - if you put something along the lines of this and what you said in an answer I will award the bounty for your help. – Ethan Mar 27 '21 at 16:56
  • 2
    @Ethan [xkcd 1987](https://xkcd.com/1987/) – bad_coder Mar 27 '21 at 19:08

1 Answers1

4
  1. Something might be broken with my Virtual Environments

The easiest solution is using a venv - it's standard library and thus the best baseline for virtual enviorments. (For completness it's worth mentioning that historically there have been a number of solutions for this.) As an example creating a venv with the PyCharm GUI is easy, it creates a new interpreter from the base Python interpreter optionally sharing its site-packages. The GUI lets you interface with PyPI to install aditional packages.

Eventually, it's worth learning to do the same using the command line, see venv — Creation of virtual environments. This boils down to 3 commands

  1. Create the venv (since you have Python on your PATH)

    c:\>python -m venv c:\path\to\myenv

  2. Activate the venv (this is OS specific, see the documentation)

    <venv>/bin/activate

  3. After activating use pip to install any libraries you want

    pip install library_name

After having the venv created and activated it's ready to use on the terminal (inside or outside PyCharm), or you can use it with run configurations in PyCharm.

Now, in your case you are also using Anaconda, which manages the packages and the environments for you. But it's important to realize that what Anaconda does for the most part are the above steps wrapped in it's own GUI, see the similarities with Finding your Anaconda Python interpreter path.

Besides this, there's a hard rule that venvs should not be copied or moved. They have hardcoded paths inside them that will break. So, when you create a venv use it in the directory where you created it. The whole point of venvs is that if you break something you simply create a new one on-the-fly. Eventually, you'll want to write your own shell script to automate creating venvs.

  1. Something might be broken with my PATH
PATH=
/Library/Frameworks/Python.framework/Versions/3.9/bin:
/Library/Frameworks/Python.framework/Versions/3.9/bin:
/Library/Frameworks/Python.framework/Versions/3.9/bin:
/Library/Frameworks/Python.framework/Versions/3.9/bin:
/Users/my_name/opt/anaconda3/bin:
/Users/my_name/opt/anaconda3/condabin:
/anaconda3/bin:
/Library/Frameworks/Python.framework/Versions/3.6/bin:
/Library/Frameworks/Python.framework/Versions/3.6/bin:
/Library/Frameworks/Python.framework/Versions/3.6/bin:
/Library/Frameworks/Python.framework/Versions/3.6/bin:
/usr/local/bin:
/usr/bin:/bin:
/usr/sbin:
/sbin:
/Library/TeX/texbin:
/Library/Apple/usr/bin

On macOS/Linux the colon : is used as the path separator. So if we break your PATH environment variable into individual lines we see you have Python 3.9 and Python 3.6 repeated (might be different micro versions, check by running the executable in each directory with python --version). The meaning of the path names is well explained in 4. Using Python on a Macintosh

To avoid any mix-up I only have the latest Python version on my PATH. Any other base Python version I need is chosen transparently by activating the right venv.

You also have the bin paths to Anaconda, check inside those to see what Anaconda makes executable. Besides that you have the normal OS stuff at /Library/Apple/usr/bin which shouldn't interfere with anything related to Python development.

Finally, module discovery is more dynamic than just what's in your PATH. The module search path sys.path gets populated with the path from where you execute a script, meaning any module/package on directory\where_you_execute\python your_script.py is discoverable (you can check it at run-time).

  1. Something might be broken trying to manage multiple Python versions on my computer

Here is where it gets complicated. If you work with different interpreters, package versions, etc...Eventually you'll want to get a 3rd party tool that helps manage all that, which would be Anaconda, or Virtualenv or Poetry or etc...But essentially what all these do is managing venvs adding functionality and complexity, it's important to learn how to create and manage venvs manually to better understand what those tools are doing for you.

Finally, the PyCharm IDE itself is implemented in Java. When you launch the IDE it has its own executable and it's a rare case that something related to a Python interpreter should make the IDE crash at launch. On the up side you know the culprit is one of your Python interpreters, namely from the error message:

Python Version: 3.6.4 (3.6.4)

and the specific error says it all (either the files were moved, or some error broke the links):

"Reason: image not found".

If you can't launch the IDE to solve the problem from within get rid of any references to the problematic interpreter by editing the configurations files. I don't know how to do this exactly, but if you're using Anaconda it should be possible to launch the Anaconda GUI from outside the IDE to also get rid of the problematic interpreter.

As a side note, if you run into problems due to having several interpreters on the PATH use the which python command on bash, or the where python command on Windows. What this will tell you is which Python interpreter on your PATH is being called when you or some application execute python something on the command line.

I don't think this question (or the other linked questions) have enough info to fully diagnose the problem. It would require an in-depth look at the exact Anaconda configurations - but the same error was also reported by brew users.

The most likely scenario is that when you launch PyCharm the list of interpreters gets populated and that calls Anaconda. At one point after upgrading to the latest Python version one of the existing environments became out of synch because it resolved to a previous base interpreter on the PATH (instead of being hardcoded to a specific installation.) Something must have gone wrong by way of an inter-package incompatibility that required a general update, something was deleted, or it was just cached that needed clearing.

bad_coder
  • 11,289
  • 20
  • 44
  • 72