manage.py“Couldn't import Django”報錯的問題解決


問題分析:

在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文件夾 虛擬環境中。

 

 

 

 

 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM