安装ElectrumX pip3依赖时clang执行失败,leveldb未安装
Alright, let's work through this leveldb installation error you're facing while setting up your Electrum server. That clang failure almost always happens because you're missing the system-level development libraries and build tools that the Python leveldb wrapper needs to compile properly. Here's how to fix it step by step:
Step 1: Install System-Level Dependencies
First, you need to install the underlying leveldb library and essential build tools for your operating system:
For Debian/Ubuntu-Based Systems
Run this command to update your package list and install the required dependencies:
sudo apt-get update && sudo apt-get install libleveldb-dev build-essential
libleveldb-devprovides the header files and libraries needed to compile the Python leveldb package.build-essentialincludes clang, gcc, and other tools required for compiling native extensions.
For macOS (Using Homebrew)
If you're on a Mac, use Homebrew to install the precompiled leveldb library:
brew install leveldb
This avoids the need to compile leveldb from source, which is often the root cause of the clang error. If you don't have Homebrew installed, you'll need to set that up first.
Step 2: Reinstall the Python Packages
Once the system dependencies are in place, re-run your original pip3 command to install the packages:
pip3 install aiohttp pylru leveldb plyvel
If plyvel Still Fails to Install
In some cases, plyvel might need explicit paths to the leveldb libraries. On macOS, try running this instead:
LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" pip3 install plyvel
This tells the compiler exactly where to find the leveldb files.
Step 3: Verify the Installation
After running the install command, check if leveldb and plyvel are now listed in your pip packages:
pip3 list | grep -E "leveldb|plyvel"
You should see both packages with their version numbers if the installation succeeded.
Additional Troubleshooting Tips
- Update Clang/Command Line Tools (macOS): If you're still hitting clang errors, make sure your Command Line Tools are up to date by running
xcode-select --install. - Use a Virtual Environment: If you're installing packages system-wide, consider using a virtual environment to avoid conflicts with existing Python packages. Activate your venv before running the pip commands.
内容的提问来源于stack exchange,提问作者Leon Gaban

