1
error   zb1.buildup     1   0   Unable to import 'application'

Here is the screenshot of my structure. It's screaming about all my imports from my current project. Does it not add the project as a path?

I know pylint is a static code checker but this feels obviously wrong. Let me know if I made a mistake of on my part. Thank you!

P.S. Just in case here is the pylint command pylint --output-format=html ../zb1 > pylint.html . Also code works, just in case you are wondering.

buildup.py

from application import app, db #import app

if __name__ == "__main__":
    db.create_all()

Screenshot

$ pylint --version
No config file found, using default configuration
pylint 1.6.4,
astroid 1.4.7
Python 3.5.2 (default, Jun 29 2016, 13:43:58)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
c3cris
  • 1,276
  • 2
  • 15
  • 37

1 Answers1

1

You're having an issue with the python search path. A relatively simple solution is to define the PYTHONPATH environment variable. Assuming that you're trying to invoke pylint from within zb1, the following should work:

PYTHONPATH=`pwd` pylint --output-format=html ../zb1 > pylint.html

The addition at the beginning of the line defined the PYTHONPATH environment variable for that invocation of pylint.

0 _
  • 10,524
  • 11
  • 77
  • 109
John Percival Hackworth
  • 11,395
  • 2
  • 29
  • 38
  • I thought when running python it always adds the PWD as a path. Or is this because I am running a diff app at my project? Can i add this as a config? or do you have a link to documentation so I can further read – c3cris Jul 29 '16 at 23:12
  • The PYTHONPATH is from the python docs. The search path for pylint is apparently based of of the location of the file you're starting the analysis from. – John Percival Hackworth Jul 29 '16 at 23:28
  • Gotcha, I see it. Would of this worked if I hacked it in the python app? using os.path.append("PWD"). Also I did start pylint from the location of the project. – c3cris Jul 29 '16 at 23:31
  • Maybe, but it's best to not muck with os.path if you don't have too. It's probably worth spending some time with the pylint docs https://pylint.readthedocs.io/en/latest/ – John Percival Hackworth Jul 29 '16 at 23:35
  • Yeah those docs are subpar! I read then in 15 min with no help. It seems hacky to force a path to PYTHONPATH. The reason is I use venv to isolate projects. It just seems counter productive :( – c3cris Jul 29 '16 at 23:37
  • Well, pylint's docs are sketchy at best... Given that pylint probably manages the python path for its analysis, the best you can do short of code changes is probably augmenting the PYTHONPATH. You could try altering buildout to import from zb1.application which would work, but would likely cause other issues. – John Percival Hackworth Jul 29 '16 at 23:47
  • I found a good answer for setting up pylint http://stackoverflow.com/a/3065082/1026880 – c3cris Jul 29 '16 at 23:53