“Go to definition” from PyDev not work in External Library files

放肆的年华 提交于 2021-01-28 16:44:58

问题


When I am in certain files, for example, External Library files, I am getting this behavior where the Go To Definition command jumps me to the import statement at the top of the file instead of opening the file with the real definition.

For example, I'm in an external library, (jumped here using Go To Definition), and from here, I again want to jump, so I put the cursor on the return statement on the Something token and hit "Go To Definition"...

from external.library.mod import Something
...
def scoped_session(arg):
    ...
    return Something(arg)

... which jumps me to the "from external.library.mod import Something" statement at the top of the file. I have the paths and sub-paths defined in External Libraries for the project.

I expect it to instead open the actual definition in the given package/file instead of jumping to the import statement.


Ubuntu 11.10, Eclipse 3.7.1, PyDev 2.4.0, Python 2.7.2


回答1:


In Eclipse, for python project; we can jump to respective module (source file) and method (function definition). For this, we need to add the packages into PyDev – PYTHONPATH.

Project -> Properties -> PyDev – PYTHONPATH -> Add source folder Browse the particular package (source folder) from Project

Once done, just click on the search keyword, which you want to search and press F3. Else press Ctrl key and click on the search keyword.

Note: Better once restart the Eclipse.




回答2:


Go to Preferences -> PyDev -> Interpreter (Whichever)

When you first configure PyDev, it scans your system folders for modules (and in some cases I think it'll ask if you you want to scan 'everything' or not..), if the libraries you want were installed after you configured your interpreter, PyDev may just not know about them.

The quickest way to do it is to select all the libraries under site-packages, remove them, and then re-add the site-packages directory so it'll rescan everything.

Alternatively, just remove the config for your python binary and reinitialize your interpreter.



来源:https://stackoverflow.com/questions/9206296/go-to-definition-from-pydev-not-work-in-external-library-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!