Code-Completion for e.g. Numpy, SciPy or Matplotlib does not work in Eclipse PyDev

£可爱£侵袭症+ 提交于 2019-12-10 10:23:08

问题


Can't get code-completion to work for e.g. SciPy, Numpy or Matplotlib in Eclipse/PyDev under Ubuntu 12.4 or 11.4. Tried with Eclipse Helios and Juno, PyDev in latest version (2.6).

Code completion does work for e.g. internal project references or builtins.

Have added path to "Preferences->Pydev->Interpreter - Python->Libraries" and added scipy, numpy and matplotlib to the "Forced Builtins". Under "Preferences->PyDev->Editor->Code Completion" "Minimum Number of chars..." is set to 1, "Preferences->PyDev->Editor->Code Completion (ctx insensitive and tokens)" "Number of chars for..." are both set to 2.

Importing and code completion works within ipython shell, so I think it must be something in PyDev...

Example code:

import numpy as np
myArr = np.array([1,2,3])
myArr.set#<hit CTRL-SPACE for completion>

Code-completion does not suggest any of the array methods here (setasflat, setfield, setflags).

Thanks for any suggestions... :)

Regards, Carsten


回答1:


I think this happens because pydev couldn't figure out what type is returned by the np.array method. If your code is long and you want code completion many times, perhaps you could "tell" pydev what is myArr's type. Try using assert:

import numpy as np
myArr = np.array([1,2,3])
assert isinstance(myArr, np.ndarray)
myArr.set#<hit CTRL-SPACE for completion>

After that code completion will always work for the myArr variable. Later you can delete or comment the assert line or use the "-O" flag with the python interpreter. Look at this page.




回答2:


Just to note, in the latest PyDev version you can now let PyDev know about the type through documentation (without needing the assert isinstance).

See: http://pydev.org/manual_adv_type_hints.html for details.



来源:https://stackoverflow.com/questions/11593472/code-completion-for-e-g-numpy-scipy-or-matplotlib-does-not-work-in-eclipse-pyd

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