$ ~/.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…
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.
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.
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.
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.
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
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
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?
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
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.
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.