You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Debian安装Cython后apt-get报错:Sub-process /usr/bin/dpkg返回错误码

Fixing "Sub-process /usr/bin/dpkg returned an error code" on Debian After Cython Installation Fail

Hey, I’ve been in this exact spot before—installing a package (like Cython) that crashes mid-install, and suddenly every apt or dpkg command throws errors. Don’t panic, let’s work through this step by step to get your system back on track.

1. Back Up & Reset Dpkg’s Corrupted State

Half-installed packages often leave dpkg’s status files in a broken state. First, we’ll back up the current state (just in case) then reset it:

  • Backup the critical dpkg files:
    sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.bak
    sudo cp /var/lib/dpkg/available /var/lib/dpkg/available.bak
    
  • Delete the corrupted state files:
    sudo rm /var/lib/dpkg/status
    sudo rm /var/lib/dpkg/available
    
  • Regenerate clean state files:
    sudo dpkg --clear-avail
    sudo apt-get update
    

Since the problem started with Cython, let’s target any partial or broken Cython packages:

  • First, list all packages in a messed-up state (half-installed, unpacked, failed config):
    dpkg -l | grep -E '(half-installed|unpacked|failed-config)'
    
  • If you see cython or python3-cython in the list, force remove them. Start with the gentler force flag, then escalate if needed:
    sudo dpkg --remove --force-remove-reinstreq cython python3-cython
    
    If that fails due to dependency errors, use the more aggressive force flag:
    sudo dpkg --remove --force-all cython python3-cython
    

3. Fix Broken Apt Sources List

You mentioned cat /etc/apt/sources.list has issues—let’s repair that too:

  • First, back up your current sources list:
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  • Now, replace it with a standard sources list for your Debian version. Find your version codename with lsb_release -c (e.g., bookworm for Debian 12, bullseye for 11). Here’s an example for Debian 12:
    echo "deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware" | sudo tee /etc/apt/sources.list
    echo "deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware" | sudo tee -a /etc/apt/sources.list
    echo "deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" | sudo tee -a /etc/apt/sources.list
    
    Swap bookworm with your actual codename if needed.

4. Run Standard Repair Commands

Now let’s run the usual dpkg/apt repair commands to clean up any remaining issues:

  • Reconfigure all unconfigured packages:
    sudo dpkg --configure -a
    
  • Fix broken dependencies:
    sudo apt-get install -f
    
  • Finally, update and upgrade to make sure everything is working:
    sudo apt-get update && sudo apt-get upgrade -y
    

Last Resort: Reinstall Dpkg Itself

If none of the above works, your dpkg binary might be corrupted. Let’s reinstall it:

sudo apt-get download dpkg
sudo dpkg -i --force-all dpkg*.deb

Then repeat step 4 to finish the repair.


内容的提问来源于stack exchange,提问作者Aleksi Väisänen

火山引擎 最新活动