简体   繁体   English

如何在Eclipse中的Pydev python项目中导入pydevd

[英]How to import pydevd in Pydev python project in eclipse

I am in windows 10 and have installed Eclipse Pydev for python projects. 我在Windows 10中,已经为python项目安装了Eclipse Pydev。 I have a raspberry pi for which I am doing python projects. 我有一个树莓派,我正在为此做python项目。 I have read somewhere that installing eclipse on raspbian os is not a good idea as it works very slow. 我在某处读到在raspbian os上安装eclipse并不是一个好主意,因为它的工作非常缓慢。 So I am looking for a solution where I can remotely debug python applications on pi. 因此,我正在寻找一种可以在pi上远程调试python应用程序的解决方案。

For this I know pydev provides pydevd for remote debugging. 为此,我知道pydev提供pydevd进行远程调试。 But I am having trouble importing pydevd . 但是我在导入pydevd时遇到了麻烦。 I have created a new pydev python project and used below code: 我创建了一个新的pydev python项目,并使用了以下代码:

import os

import pydevd

pydevd.settrace("EclipseIDE_HOSTNAME", port=5678)

But it shows error in 2nd line. 但是它在第二行显示错误。 Unresolved import pydevd . Unresolved import pydevd I thought its already included in pydev but looks like I need to install pydevd externally. 我认为它已经包含在pydev中,但是看起来我需要在外部安装pydevd。 But how to do that. 但是该怎么做。 Can anyone please help me here. 任何人都可以在这里帮助我。 Thanks.! 谢谢。!

EDIT: 编辑:

import sys;sys.path.append(r'C:\Users\Andrew\.p2\pool\plugins\org.python.pydev_5.8.0.201706061859\pysrc')
import pydevd;pydevd.settrace("192.168.137.179", port=5678)

I am also relying on pydevd for my day to day work and as far as I know you are right to assume that it is included in the pydev plug in for eclipse. 我还依靠pydevd进行日常工作,据我所知,您可以正确地假定它已包含在Eclipse的pydev插件中。 However the plug in under eclipse does autocompletion by inserting 但是,eclipse下的插件会通过插入来自动完成

import sys
sys.path.append(<internal path to pydevd>)
import pydevd; pydevd.settrace()

which is only natural as the plug in is not available to the standard Python interpreter by design. 这是很自然的,因为设计使标准Python解释器无法使用该插件。

The internal path includes the version of the plug in, that's why I can't give you an exact string. 内部路径包括插件的版本,这就是为什么我无法为您提供确切的字符串。 I recommend that you search through the internals of pydev to find the correct path. 我建议您在pydev的内部进行搜索以找到正确的路径。

Another solution would be to add the path to pydevd to the environment variables PYTHOPATH which I would discourage as it is absolutely not pythonic and makes it not obvious for other developers how to make your code work! 另一个解决方案是将pydevd的路径添加到环境变量PYTHOPATH中,我不鼓励这样做,因为它绝对不是pythonic的,并且对其他开发人员来说,如何使代码正常工作也不明显!

Here is how you can do remote debug python scripts on pi from eclipse (windows): 这是您可以从Eclipse(Windows)在pi上进行远程调试python脚本的方法:

Install eclipse and pydev 安装eclipse和pydev

Install pydevd on pi using pip install pydevd 使用pip install pydevd在pi上安装pydevd

In eclipse, create a new python project and add below lines at starting of the code: 在eclipse中,创建一个新的python项目,并在代码开头添加以下行:

import sys;sys.path.append(<path to pydevd>)
import pydevd;pydevd.settrace(<ip address of windows>, port=5678)

Write your python code and copy the same python file on pi. 编写您的python代码,然后在pi上复制相同的python文件。

Open debug perspective and start the pydevd debugger by clicking on pydev from menu options. 打开调试透视图,然后通过从菜单选项中单击pydev来启动pydevd调试器。

Now execute python code on pi. 现在在pi上执行python代码。

It will automatically stop after settrace in eclipse. 在eclipse中的settrace之后,它将自动停止。

From now onwards you can step into your code and debug it. 从现在开始,您可以进入您的代码并对其进行调试。

Happy debugging :) 调试愉快:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM