Strange mixing system + homebrew Python with LLDB

When I try to run the Python interpreter in lldb, I see:

$ lldb
(lldb) script
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in <module>
    import weakref
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.

When I check which version of Python was running, Python reports that it should be Python Homebrew (which is symbolically attached to this place):

>>> sys.executable
'/usr/local/opt/python/bin/python2.7'

However, asking for a version of Python returns the version associated with setting Python by default, for example.

>>> sys.version_info
sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

And, just to confirm, the version of Python on the binary path above is really different (note the difference in the micro version):

$ /usr/local/opt/python/bin/python2.7 --version
Python 2.7.14

$ /usr/bin/python --version
Python 2.7.10

To make things more confusing, a name _remove_dead_weakrefexists in the module _weakreffor my installation on Homebrew Python, but not for the default installation:

$ /usr/bin/python -c "import _weakref; print _weakref._remove_dead_weakref"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '_remove_dead_weakref'

$ /usr/local/opt/python/bin/python2.7 -c "import _weakref; print _weakref._remove_dead_weakref"
<built-in function _remove_dead_weakref>

, Python LLDB? ?

+20
4

LLDB Python PATH,

PATH=/usr/bin /usr/bin/lldb

, LLDB PATH "" Python; Python, PATH, , LLDB Python.

+14

lldb DYLD_PRINT_LIBRARIES=1, , Python.framework /System/Library, Python Homebrew:

dyld: loaded: /System/Library/Frameworks/Python.framework/Versions/2.7/Python
...
dyld: loaded: /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_locale.so

DYLD Python.framework Homebrew, :

DYLD_FRAMEWORK_PATH="$(brew --prefix python@2)/Frameworks/" "$(xcrun -f lldb)"

macOS 10.13.6 brew'd Python 2.7.15.

: , DYLD_FRAMEWORK_PATH Xcode, /usr/bin. , xcrun -f lldb, LLDB.

+7

brew unlink python@2 . Homebrew Python 2.x PATH. Homebrew Homebrew Python 2.x, brew Python 2.x, lldb.

Homebrew Homebrew Bundle, Brewfile:

brew "python@2", link: false
+4

I solved this problem by uninstalling python@2from Homebrew: https://github.com/flutter/flutter/issues/17803#issuecomment-390980648

UPD:

As @Olsonist noted in the comments, executing this command should solve this problem: brew uninstall --force python@2

0
source

Source: https://habr.com/ru/post/1690278/


All Articles