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

升级Ubuntu17.04至17.10后PyCharm运行Django项目报_remove_dead_weakref导入错误

Fixing ImportError: cannot import name '_remove_dead_weakref' After Ubuntu Upgrade

Hey there, let's sort out this frustrating error you're hitting after upgrading Ubuntu 17.04 to 17.10 and trying to run your Django project in PyCharm.

What's causing this?

This error almost always boils down to a corrupted Python virtual environment. When you upgrade your Ubuntu system, it often updates system-level Python components. Since virtual environments rely on links to some system Python files, these updates can break the dependencies in your existing venv—leading to weird import errors like the one you're seeing with _remove_dead_weakref from _weakref.

Step-by-Step Fix

Here's how to get your project back up and running:

  1. Backup your existing virtual environment (optional but safe)
    Make a copy of your venv folder just in case something goes wrong:

    cp -r /home/encuentrum/venv-encuentrum3 /home/encuentrum/venv-encuentrum3_backup
    
  2. Delete the corrupted virtual environment
    Get rid of the broken venv:

    rm -rf /home/encuentrum/venv-encuentrum3
    
  3. Create a fresh virtual environment
    Recreate the venv using Python 3.6 (matching your original setup):

    python3.6 -m venv /home/encuentrum/venv-encuentrum3
    
  4. Activate the new venv and reinstall dependencies

    • Activate the environment:
      source /home/encuentrum/venv-encuentrum3/bin/activate
      
    • If you have a requirements.txt file for your project, install all dependencies at once:
      pip install -r /home/encuentrum/GitLab/encuentrum3/ENCUENTRUM/requirements.txt
      
    • If you don't have a requirements file, manually install Django and any other packages your project needs (e.g., pip install django).
  5. Update PyCharm's interpreter configuration
    Open PyCharm and navigate to:

    File > Settings > Project: ENCUENTRUM > Python Interpreter

    • Click the gear icon → Add
    • Select "Existing environment" and browse to the new venv's Python executable: /home/encuentrum/venv-encuentrum3/bin/python
    • Save the configuration.
  6. Test running your Django server
    Try launching the server again in PyCharm—this should resolve the import error.

内容的提问来源于stack exchange,提问作者Miguel Halanoca Ramos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:27:27