铜仁市网站建设_网站建设公司_导航易用性_seo优化
2026/1/21 17:47:23 网站建设 项目流程

报错

命令:python manage.py runerver 0.0.0.0:8001
原因:django版本更新,需要使用更高版本的sqlite,但是sqlite在python中被内置,无法直接升级卸载

Traceback (most recent call last): File "/home/project/new_django/manage.py", line 11, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/project/new_django/manage.py", line 22, in <module> main() File "/home/project/new_django/manage.py", line 13, in main raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment

快速修复(可直接复制执行)

系统 SQLite 太旧,需用 pysqlite3 替代内置 sqlite3

  • 安装替代库:

source .venv/bin/activate # 激活对应的虚拟环境
pip install pysqlite3-binary

  • 在虚拟环境的 site-packages 放置 sitecustomize.py:

SITE_PACKAGES=$(python -c ‘import sysconfig; print(sysconfig.get_paths()[“purelib”])’)

cat > “$SITE_PACKAGES/sitecustomize.py” <<‘PY’
import pysqlite3 as sqlite3
import sys
sys.modules[‘sqlite3’] = sqlite3
sys.modules[‘sqlite3.dbapi2’] = sqlite3.dbapi2
PY

  • 验证:

python -c ‘import sqlite3; print(sqlite3.sqlite_version)’

实测后效果,可用

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询