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.

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