Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 481
Carsten König Avatar asked Jun 20 '26 09:06

Carsten König


2 Answers

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.

like image 112
jheyse Avatar answered Jun 22 '26 21:06

jheyse


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.

like image 29
Fabio Zadrozny Avatar answered Jun 22 '26 21:06

Fabio Zadrozny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!