You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 18.04+Python3.7.3导入pandas报_lzma模块未找到错误求助

Fixing "_lzma module not found" Error When Importing Pandas on Ubuntu 18.04 (Python 3.7.3)

Hey there, let's work through this tricky _lzma module issue you're hitting with pandas. Even though _lzma isn't listed as a direct pandas dependency, it's likely being pulled in indirectly—either by a pandas sub-dependency or when pandas tries to handle compressed file formats like .xz. Here's how to resolve it:

Step 1: Ensure System-Level LZMA Libraries Are Installed

Python's _lzma module relies on the system's liblzma-dev package. Even if you think it's installed, re-installing it ensures all dependencies are intact:

sudo apt-get update && sudo apt-get install --reinstall liblzma-dev

Step 2: Verify Python Can Access the _lzma Module

First, check if the module path is in Python's system path. Fire up a Python 3.7 shell and run:

import sys
print("/usr/lib/python3.7/lib-dynload" in sys.path)

If this returns False, you can add the path temporarily (for the current session) with:

sys.path.append("/usr/lib/python3.7/lib-dynload")

To make this permanent, add the following line to your ~/.bashrc file:

export PYTHONPATH="$PYTHONPATH:/usr/lib/python3.7/lib-dynload"

Then reload your shell with source ~/.bashrc.

Step 3: Recompile Python 3.7.3 (If Needed)

If the above steps don't work, the problem might be that your Python 3.7.3 was compiled without linking to the system LZMA libraries. Here's how to recompile it properly:

  1. Download the Python 3.7.3 source code (if you don't already have it):
    wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
    tar xzf Python-3.7.3.tgz
    cd Python-3.7.3
    
  2. Configure the build to explicitly include LZMA support:
    ./configure --with-lzma
    
  3. Compile and install (use altinstall to avoid overwriting your system's default Python):
    sudo make && sudo make altinstall
    

Step 4: Reinstall a Python 3.7-Compatible Pandas Version

Sometimes version mismatches can cause odd dependency issues. Try installing a pandas version that's confirmed to work with Python 3.7:

pip3 uninstall -y pandas
pip3 install pandas==1.3.5

Why This Happens

Even though _lzma isn't a direct pandas dependency, pandas uses Python's standard library lzma module under the hood when working with compressed files. If your Python build didn't properly link to the system's LZMA libraries during compilation, the module file might exist but fail to load when called.

内容的提问来源于stack exchange,提问作者Marco Dalla Gasperina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:14:29