問題分析:
在pyharm中項目可以正常運行但是在終端 終端輸入python manage.py runserver首次測試項目時,出現了無法引用Django的錯誤。
Traceback (most recent call last): File "manage.py", line 8, in <module> from django.core.management import execute_from_command_line ImportError: No module named 'django' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 14, in <module> import django ImportError: No module named 'django' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 17, in <module> "Couldn't import Django. Are you sure it's installed and " 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?
可能出現的問題:
- 有不同版本的Python,當前項目使用了沒有安裝Django的Python。
- 創建的虛擬環境時,沒有導入之前下載的包,導致在環境下搜索不到Django。
- Django版本過低。
解決方案:
將pyharm文件夾下site-packages中所有的文件復制一份到python的Lib文件夾 虛擬環境中。


然后就可以在終端跑起你的項目咯

