LoginSignup
0
0

More than 5 years have passed since last update.

Djangoインストール時に、ModuleNotFoundErrorが起きる時の対処法

Last updated at Posted at 2019-05-03

はじめに

Djangoインストール時にModuleNotFoundErrorが起きた時に考えられる原因と対処法を説明します。

開発環境

OS:macOS Mojave(10.14.4)
Django==2.1.7

ModuleNotFoundErrorが起きた時に考えられる原因はpythonが参照できるディレクトリにDjangoが存在しないことです。

まずは、以下の対話的コマンドでpython(ここではpython3)が参照可能なディレクトリを確認します。

$ python3
Python 3.7.2 (default, Mar 18 2019, 17:25:47)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/Users/user/.pyenv/versions/3.7.2/lib/python37.zip', '/Users/user/.pyenv/versions/3.7.2/lib/python3.7', '/Users/user/.pyenv/versions/3.7.2/lib/python3.7/lib-dynload', '/Users/user/hoge/Django/hoge/fuga_venv/lib/python3.7/site-packages']

次に、以下のコマンドでDjangoがあるディレクトリを確認します。

$ pip3 show django
Name: Django
Version: 2.2.1
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD
Location: /Users/user/hoge/Django/hoge/fuga_venv/lib/python3.7/site-packages
Requires: pytz, sqlparse
Required-by:

ここでDjangoのパスをpython3が参照可能でなければ、(今回の事例では参照可能になっています。)パスを変更するなりの対処をします。インストール先のpythonのバージョンが異なるとかもありえますので、その時は適切なバージョンのpythonに切り替えてからDjangoを再度インストールしてあげましょう。

パスの設定に関してはこちらの記事が参考になります。
MacでPATHを通す

pythonのバージョン切り替えに関してはこちらの記事を参考ください。
pyenvにより、pythonのバージョンを変更する

0
0
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
0
0