在PyCharm中调试Vagrant下的Python/Django

11 投票
1 回答
2214 浏览
提问于 2025-04-18 01:34

我正在尝试在Vagrant中调试一个Django项目。

我已经搜索了很多答案,并阅读了关于Vagrant、使用Pycharm进行远程调试等所有可用的文档。

现在我有一个完全正常工作的“运行”命令:

ssh://vagrant@127.0.0.1:2222/home/vagrant/dev-projects/OP_3.0/bin/python2.7 -u
 /home/vagrant/dev-projects/3.0/online_platform/manage.py runserver 8000

0 errors found
April 06, 2014 - 02:32:40
Django version 1.6.2, using settings 'local_settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

我可以从主机访问它,一切都按预期工作。
但是当我尝试运行“调试”命令时,我遇到了这个:

ssh://vagrant@127.0.0.1:2222/home/vagrant/dev-projects/OP_3.0/bin/python2.7 -u
 /home/vagrant/pydev/pydevd.py --multiproc --client '0.0.0.0' --port 34117 --file /home/vagrant/dev-projects/3.0/online_platform/manage.py runserver 8000

Traceback (most recent call last):
  File "/home/vagrant/pydev/pydevd_comm.py", line 310, in OnRun
    self.handleExcept()
  File "/home/vagrant/pydev/pydevd.py", line 1414, in handleExcept
    ReaderThread.handleExcept(self)
  File "/home/vagrant/pydev/pydevd_comm.py", line 329, in handleExcept
    GlobalDebuggerHolder.globalDbg.FinishDebuggingSession()
AttributeError: 'NoneType' object has no attribute 'FinishDebuggingSession'
Traceback (most recent call last):
  File "/home/vagrant/pydev/pydevd.py", line 1497, in <module>
    dispatcher.connect(host, port)
  File "/home/vagrant/pydev/pydevd.py", line 1400, in connect
    self.reader.run()
  File "/home/vagrant/pydev/pydevd_comm.py", line 252, in run
    self.OnRun()
  File "/home/vagrant/pydev/pydevd_comm.py", line 325, in OnRun
    self.handleExcept()
  File "/home/vagrant/pydev/pydevd.py", line 1414, in handleExcept
    ReaderThread.handleExcept(self)
  File "/home/vagrant/pydev/pydevd_comm.py", line 329, in handleExcept
    GlobalDebuggerHolder.globalDbg.FinishDebuggingSession()
AttributeError: 'NoneType' object has no attribute 'FinishDebuggingSession'

Process finished with exit code 1`

请任何人提供真正的帮助……

1 个回答

3

如果你想要这样做:

  1. 让你的PyCharm项目配置知道这个项目使用的vagrant盒子
  2. 设置一个远程解释器,类型选择Vagrant,并指向vagrant盒子里的正确Python可执行文件
  3. 把这个远程解释器当作你项目的Python解释器来用

那么你就不需要再自己去折腾ssh和调试命令行了。只需告诉PyCharm你想调试什么,就像是在调试本地进程一样。(如果你还告诉PyCharm这是一个Django项目,可能效果会更好。)

撰写回答