Swift repl: no module named lldb

$ ~/.swiftenv/versions/5.7-RELEASE/usr/bin/swift repl
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb'
error: failed to launch REPL process: 'A' packet returned an error: 8

i understand the REPL has never worked on the nightlies, but i at least expected it to work out of the box in the 5.7 release toolchain…

1 Like

same issues
workaround method is install lldb
and make soft link dist-packages

sudo ln -s /usr/lib/llvm-14/lib/python3.10/dist-packages /usr/local/lib/swift-5.7-RELEASE-ubuntu22.04/usr/lib/python3/dist-packages
1 Like

@taylorswift are you seeing this on Linux?

I have the same issue. On Ubuntu 18.04 in my case.

Swift compiler hasn't shipped with LLDB Python binding since 5.6.x. I just checked 5.7 package, no LLDB Python binding neither. You have to compile yourself. However, repl doesn't require Python LLDB binding before, so I am unsure why it becomes an issue and why @Kila2 's workaround would work.

yes, on an Amazon Linux 2 docker. i originally thought it was a docker issue because of a missing --cap-add SYS_PTRACE, but that did not fix the issue.

it seems… unhealthy (to say the least) for swift to be shipping a broken playground by default?

1 Like

FWIW, I tested it with 5.7-RELEASE on Fedora 36 and it works properly.

I am not sure if it is REPL doesn't work out of box (as I said, Python LLDB binding is not required for 5.6's REPL I tested) or there are some setups in your .lldbinit somehow requires Python LLDB binding though. Thus, I am not in authority to say it is a broken playground by default.

However, without Python LLDB binding I believe that does make VSCode debugger integration stranger on Linux (I don't use that though). It also makes my Jupyter notebook usage harder, but I guess I am on my own there anyway.

Installing the python3-lldb-13 package helped me.
https://ubuntu.pkgs.org/20.04/ubuntu-proposed-universe-amd64/python3-lldb-13_13.0.1-2ubuntu2~20.04.1_amd64.deb.html

1 Like

I can confirm that installing python3-lldb-13 helps, but it's only available for Ubuntu 22.04 by default, apt-get install -y python3-lldb-13 will fail on Focal and earlier Ubuntu LTS releases.

As for the Docker image, there's a PR for the fix now: Fix broken `lldb` and `swift repl` in Ubuntu Jammy by MaxDesiatov · Pull Request #317 · apple/swift-docker · GitHub.

1 Like

I'm getting this error in Swift 5.8 (on Ubuntu 18.04), but the repl still launches:

$ swift repl
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb'
Welcome to Swift version 5.8 (swift-5.8-RELEASE).
Type :help for assistance.
  1> ["Hello", "World!"].joined(separator: ", ") 
$R0: String = "Hello, World!"

Other swift commands (swift package init, swift build, etc) still work fine.

1 Like

I just installed Swift 5.9 on Raspberry Pi OS (Debian 12), and I get this error as well. There are several python3-lldb I can choose from. Which should I use?

$ apt search python3-lldb
Sorting... Done
Full Text Search... Done
python3-lldb/stable 1:14.0-55.7~deb12u1 arm64
  Next generation, high-performance debugger, python lib

python3-lldb-13/stable 1:13.0.1-11+b2 arm64
  Next generation, high-performance debugger, python3 lib

python3-lldb-14/stable 1:14.0.6-12 arm64
  Next generation, high-performance debugger, python3 lib

python3-lldb-15/stable 1:15.0.6-4+b1 arm64
  Next generation, high-performance debugger, python3 lib

Unfortunately, there is no suitable package for Swift 5.9.
Right now Apple LLVM is much further ahead than community LLVM.

Accordingly, the Apple LLVM 13 really is ahead of LLVM 17.

Fast hack for Swift 5.9 installed in /usr:
Copy the contents of /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb
into
/usr/lib/python3/dist-packages/lldb
Then:

cd /usr/lib/python3/dist-packages/lldb
sudo ln -s ../../../liblldb.so.13.0.0git lldb.so

You're saying to copy lldb from Xcode on macOS to Debian on Raspberry Pi? Does that even work?

And that ln step seems to be to a file different than the lldb just copied?

Yes, it works. The ...Python/lldb folder contains mostly generic platform-independent python code. Swift itself must be installed in '/usr'.

I installed python3-lldb (on my rpi4 with ubuntu it seem to be lldb 17) and instead of copying from the Xcode folder, I just copied the llvm-project/lldb/source/Interpreter/embedded_interpreter.py from the GitHub apple/llvm-project to /usr/lib/python3/dist-packages/lldb/. I am not sure if there are any gotchas, but no errors so far.
The other files are found in llvm-project/lldb/examples/python/ but if those really are needed?

To fix the swift repl lldb errors on Swift 5.9.* do the following.

  1. install python3-lldb
    sudo apt install python3-lldb

  2. find the python embedded_interpreter.py file.
    find /usr -name embedded_interpreter.py
    This should give you a location somewhere in /usr/lib/llvm-14/lib/python3.*/
    The exact location will depend on what Ubuntu/Debian distribution you are using.
    e.g. for Debian Bookworm the location is -
    /usr/lib/llvm-14/lib/python3.11/dist-packages/lldb/embedded_interpreter.py
    for Ubuntu Jammy the location is -
    /usr/lib/llvm-14/lib/python3.10/dist-packages/lldb/embedded_interpreter.py

  3. link the file to the /usr/lib/llvm-14/lib/python3/ directory -
    e.g. for Debian Bookworm -
    ln -s /usr/lib/llvm-14/lib/python3.11/dist-packages/lldb/embedded_interpreter.py /usr/lib/llvm-14/lib/python3/dist-packages/lldb/embedded_interpreter.py

swift repl should now be fixed.
There is no need to copy any files from xcode or any github repository.

If you are installing Swift on a Raspberry Pi I have just uploaded a new install package to the Swift Community Apt Repository for Debian Bookworm that includes this fix so swift repl should now work out of the box.

2 Likes

FWIW, I have just installed swiftlang on Zorin OS (compatible with ubuntu/jammy) and still found the need for manually installing and creating the softlink.