5
3

More than 1 year has passed since last update.

[django] ImportError: Couldn't import Django 解決方法

Last updated at Posted at 2022-01-10

解決方法

・Windows
作成したサイトのフォルダに移動してコマンドプロンプトで以下を実行する。

pip install django

その後以下のコマンドを実行しサーバーが動いたどうか確認。

python manage.py runserver

Starting development server at http://*********
と表示されれば動作確認完了。解決できた。

参考サイト
https://docs.djangoproject.com/ja/4.0/intro/tutorial01/

この記事を書いたいきさつ

Django を使用したかったが使用できなくて困っていた。
Django サーバー起動時にコマンドプロンプトで python manage.py startapp を実行すると import エラーとなった。

エラー文

C:\Users\***\mysite>python manage.py startapp
Traceback (most recent call last):
  File "C:\Users\***\mysite\manage.py", line 10, 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 "C:\Users\***\mysite\manage.py", line 21, in <module>
    main()
  File "C:\Users\***\mysite\manage.py", line 12, 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?

使用したバージョン

py -m django --version
4.0.1
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3