简体   繁体   中英

How to import pydevd in Pydev python project in eclipse

I am in windows 10 and have installed Eclipse Pydev for python projects. I have a raspberry pi for which I am doing python projects. I have read somewhere that installing eclipse on raspbian os is not a good idea as it works very slow. So I am looking for a solution where I can remotely debug python applications on pi.

For this I know pydev provides pydevd for remote debugging. But I am having trouble importing pydevd . I have created a new pydev python project and used below code:

import os

import pydevd

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

But it shows error in 2nd line. Unresolved import pydevd . I thought its already included in pydev but looks like I need to install pydevd externally. 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. However the plug in under eclipse does autocompletion by inserting

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.

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.

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!

Here is how you can do remote debug python scripts on pi from eclipse (windows):

Install eclipse and pydev

Install pydevd on pi using pip install pydevd

In eclipse, create a new python project and add below lines at starting of the code:

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.

Open debug perspective and start the pydevd debugger by clicking on pydev from menu options.

Now execute python code on pi.

It will automatically stop after settrace in eclipse.

From now onwards you can step into your code and debug it.

Happy debugging :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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