Exception has occurred: 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?File "/data/mountain-backend/src/manage.py", line 8, in <module>from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'During handling of the above exception, another exception occurred:File "/data/mountain-backend/src/manage.py", line 14, in <module>import django
ModuleNotFoundError: No module named 'django'During handling of the above exception, another exception occurred:File "/data/mountain-backend/src/manage.py", line 16, in <module>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?
截图:
原因:
应用的虚拟环境:env-python3
实际用的Python3-vscode调试,导致输出错误;
解决方法:
1 单击vscode右下角:3.8.10 64-bit
2 弹出页面选择虚拟环境env的python3
选择env环境的python3执行;
再次调试即可;
本机环境;
# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal