In my script I use:
python
from pkg_resources import resource_filename
Both PyDev and pylint 0.23 complain about unresolved import here.
E0611 No name 'resource_filename' in module 'pkg_resources'
As I understand, this happens due to the fact that both PyDev and pylint perform only source code analysis, without actually trying to parse/compile it. And apparently pkg_resources
does something special to define pkg_resources
. The package and symbol are of course there, and whole thing works just fine. Two questions:
Python 2.7.1 (under OSX), distribute 0.6.19.
You can load troublesome dynamic modules by modifying your project's pydev python interpreter definition. Configure the default list of 'forced built-ins' to include dynamically generated definitions you use. Forced built-ins are generated by shelling out and loading/inspecting dynamically generated classes.
In the python interpreter definition (preferences => pydev => interpreters => python interpreter)
, select your currently used interpreter for your pydev project. Select the Forced Builtins
tab. Press the New...
button, and add pkg_resources
to the list.
I've done this, and now my errors are gone, and auto-complete of methods works ok for my project. I'm using python 2.7.9, pydev 3.3.3, and eclipse kepler r2.
For pylint, you can disable the warning globally in your project's pylint config, for the entire file, or for one instance of its use. You can add a # pylint: disable=E1101
comment at start of your file to disable it for that module, or on on the line above where you use it to just disable it for that instance. There's also a possibly time-consuming way to manually hint to pylint that your class has specific methods.
I had the same problem. For Pydev I found the answer on pydev.org: Go to the error line, hit ctrl-1, and select 'undefined variable'. It will then append a #@UndefinedVariable
comment, and the error goes away.
For pylint, disabling E1101 does the trick, pragma # pylint: disable=E1101
. Pylint pragmas just need to go at the same indent level, but the pydev comment had to be on the same line. My somewhat comment-cluttered function became:
def get_test_datafile(file_):
# pylint: disable=E1101
return pkg_resources.resource_string(__name__, #@UndefinedVariable
'testdata/'+file_)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With