【发布时间】:2026-01-25 15:15:02
【问题描述】:
我正在努力在我的 lldb 会话中添加一些 Python 脚本,但我发现它仅在 /usr/bin/python 是 PATH 上的第一个 Python 时才有效。如果我首先在 PATH 上找到了另一个 Python,那么一旦 lldb 初始化其内部 Python 系统,它将得到如下异常并终止。
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 548, in <module>
main()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
是否有一些 lldb 设置或命令可以让我不理会我的 PATH 但仍然让 lldb 使用/usr/bin/python?
我也可以通过设置PYTHONHOME=/usr 来解决这个问题,但由于我正在调试自定义 Python 构建和 Python 扩展,我真的不想改变环境。似乎应该有一些像settings set internal-python /usr/bin/python 这样的方法,我可以在我的~/.lldbinit 中输入来告诉lldb 使用什么。
【问题讨论】:
-
你可能需要设置你的路径来包含你想要使用的 python 版本的站点包和各种包含......但是我确信它可以完成(我使用 pycharm 和一些项目使用 kivy 及其版本的 python,而其他项目使用我的常规 python 安装,但我运行的是 win7,所以它可能适用于你,也可能不适用于你)(ps wxPython 很棒,我一直在使用它!)
-
是的,我也可以通过设置 PYTHONHOME 来解决它,但由于我正在调试自定义 Python 构建和 Python 扩展,我真的不想改变环境。我会稍微更新一下问题...
标签: python xcode macos xcode4.6 lldb