xref: /llvm-project/lldb/docs/resources/caveats.rst (revision 6a2552a1419d674033c8d2f8bfeeb981a70a2e67)
1Caveats
2=======
3
4.. _python_caveat:
5
6Python
7------
8
9LLDB has a powerful scripting interface which is accessible through Python.
10Python is available either from within LLDB through a (interactive) script
11interpreter, or as a Python module which you can import from the Python
12interpreter.
13
14To make this possible, LLDB links against the Python shared library. Linking
15against Python comes with some constraints to be aware of.
16
171.  It is not possible to build and link LLDB against a Python 3 library and
18    use it from Python 2 and vice versa.
19
202.  It is not possible to build and link LLDB against one distribution on
21    Python and use it through an interpreter coming from another distribution.
22    For example, on macOS, if you build and link against Python from
23    python.org, you cannot import the lldb module from the Python interpreter
24    installed with Homebrew.
25
263.  To use third party Python packages from inside LLDB, you need to install
27    them using a utility (such as ``pip``) from the same Python distribution as
28    the one used to build and link LLDB.
29
30The previous considerations are especially important during development, but
31apply to binary distributions of LLDB as well.
32
33LLDB in Xcode on macOS
34``````````````````````
35
36Users of lldb in Xcode on macOS commonly run into these issues when they
37install Python, often unknowingly as a dependency pulled in by Homebrew or
38other package managers. The problem is the symlinks that get created in
39``/usr/local/bin``, which comes before ``/usr/bin`` in your path. You can use
40``which python3`` to check to what it resolves.
41
42To be sure you use the Python that matches with the lldb in Xcode use ``xcrun``
43or use the absolute path to the shims in ``/usr/bin``.
44
45::
46
47   $ xcrun python3
48   $ /usr/bin/python3
49
50Similarly, to install packages and be able to use them from within lldb, you'll
51need to install them with the matching ``pip3``.
52
53::
54
55   $ xcrun pip3
56   $ /usr/bin/pip3
57
58The same is true for Python 2. Although Python 2 comes with the operating
59system rather than Xcode, you can still use ``xcrun`` to launch the system
60variant.
61
62::
63
64   $ xcrun python
65   $ /usr/bin/python
66
67Keep in mind that Python 2 is deprecated and no longer maintained. Future
68versions of macOS will not include Python 2.7.
69