LoginSignup
19
23

More than 5 years have passed since last update.

PyCharm で Vagrant の共有フォルダに入れている Django プロジェクトをデバッグ実行

Last updated at Posted at 2014-10-21

前提

環境

  • Mac OS X 10.10
  • PyCharm 3.4.1
  • Vagrant 1.6.5
  • VirtualBox 4.3.16

ちなみに Vagrant の box は ubuntu/trusty64。pyvenv-3.4 で仮想環境作成

  • ローカルのDjangoプロジェクトのパス
    /Users/taro/git/my_django_project

  • ローカルのvirtualenv
    /Users/taro/.virtualenvs/my_django_project_env

  • ローカルのVagrantfile
    /Users/taro/git/my_django_project/Vagrantfile

  • VagrantのDjangoプロジェクトのパス(共有フォルダなので中身は一番上の my_django_project)
    /vagrant_data

  • Vagrantfileにはこれ書いてupしておく

  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "/Users/taro/git/my_django_project", "/vagrant_data"
  • Vagrantの方でどこかにvirtualenv作ってpip installとかしておく。パスは仮に /venv

PyCharmで設定

リモートPythonインタプリタ追加

Preferences > Project Interpreter > 歯車ボタンのAdd Remote

ラジオは Vagrant を選択

Vagrant Instance Folder: /Users/taro/git/my_django_project (Vagrantfileあるとこ。今の前提ではDjangoのプロジェクトの中にあるのでここを指定している)
Python interpreter path: /venv/bin/python

Run/Debug Configuration

Django server で設定

Host: 192.168.33.10
Port: てきとう
Python interpreter: 上で追加したインタプリタ
Working directory: /vagrant_data
Path mappings:

  • /Users/taro/git/my_django_project=/vagrant_data
  • /Users/taro/.virtualenvs/my_django_project_env=/venv

設定できたらOKしてブレイクポイント指定していつものように虫ボタンでデバッグ開始。ブレイクポイントでちゃんと止まって変数の中身とか見えたらOK。ローカルにファイルが存在しないって言われたら Path mappings の設定を見直す。

注意

  • なんか設定後、色々読み込んだりして時間がかかることもあるので落ち着いて待つ
  • 最初、StackOverflow を適当に読んで pydevd の egg コピーしたり manage.py にその import 書くってやつをやったけどそれは必要なかった
19
23
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
19
23