LoginSignup
5
4

More than 5 years have passed since last update.

python manage.py runserver で開発環境でのサーバー起動時に出るSyntaxError エラーの対処法

Posted at

はじめに

python manage.py runserverコマンドを実行した時によくでる定型のSyntaxError エラーについて解説します。

開発環境

OS:macOS Mojave(10.14.4)
Django==2.1.7

python manage.py runserverコマンドを実行した時に、以下のエラーが出たことはありませんか。

$ python manage.py runserver
  File "manage.py", line 14
    ) from exc
         ^
SyntaxError: invalid syntax

このSyntaxError エラーはpythonのバージョンが2系だった場合に出るエラーになります。Django2系では、Python3系を使う必要があるのですが、python2系と3系をローカルでどちらもインストールしている場合、python3系で参照しているつもりが、python2系に切り替わってしまっている可能性があります。

まずは、以下のコマンドでバージョンを確認します。

$ python --version
Python 2.7.10

ここでpythonのバージョンが2系であれば一安心です。後は以下の記事の手順に従って、pythonのバージョンを3系に切り替えた上で再度python manage.py runserverを実行してあげましょう。
pyenvにより、pythonのバージョンを変更する

参考記事

HerokuにDjangoのプロジェクトをデプロイした時のエラーのメモ

5
4
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
4