[Qgis-user] QGIS customized importing apparently causes problems with type checkers/Intellisense

Ari Meyer ari.meyer at gmail.com
Thu Dec 16 17:05:04 PST 2021


Thank you, Richard.  Yeah, the PyCharm config is obviously different, but I
did have most of the same PYTHONPATH, PATH, etc. settings in my batch
script.  I did more searching, though, and found this gem:

https://www.gispo.fi/en/blog/cooking-with-gispo-qgis-plugin-development-in-vs-code/

In it the author had a critical note (perhaps specifically for VS Code
users):
Note 1: Currently the only one language server supporting autocompletion
for qgis and PyQt5 libraries is the Jedi language server. Qgis and PyQt5
packages are using compiled python code and other language servers are
having troubles parsing the API from those libraries (Actually this is for
security reasons).

This solved my problem!  I just assumed that all the language servers were
functionally equivalent, so I kept banging my head against a wall trying to
get it to work with M$'s recommended Pylance.  So frustrating.

He subsequently wrote:
In the following QGIS releases python stub files that describes the API are
included in the qgis package so also much better Pylance language server
can be then used. If you have *.pyi files in
C:/OSGeo4W64/apps/qgis-ltr/python/qgis go with the Pylance language server.

I do not see any *.pyi files in my 3.16.9
LTR's C:\OSGeo4W\apps\qgis-ltr\python\qgis dir nor in any of the subdirs.
Should I be?

In any case, I think this should get me by for a while.  Also, you're
definitely right that key info like this needs to go into our centralized
PyQGIS developer documentation.

Cheers!  (And thanks to lauri at gispo.fi for the blog post!)
Ari

On Thu, Dec 16, 2021 at 1:30 AM Richard Duivenvoorde <rdmailings at duif.net>
wrote:

> Hi Ari,
>
> I'm not using VS Code so sorry, cannot give specific help.
> But using Pycharm there also you need to take a lot of hoops to be able to
> use code-completion.
> See for example:
>
>
> https://qtibia.com/how-to-setup-pycharm-for-qgis-development-under-linux-and-windows/
> and
>
> https://silverspringenergy.com/using-pycharm-as-an-ide-for-qgis-3-plugin-development-2/
>
> The crux is that the editors need to build up some internal structures
> with all (possible) types and names in it, so paths from libraries (like
> PyQGIS ones) which are not in the normal python path have to be manually
> added. AND because pyqgis is actually a wrapper around c++ libs you also
> have to point to those (I think because else they do not have enough
> information).
> Also with PyCharm it is a lot of fiddling, but in the end it just works.
>
> IF you manage to make it work: let's write it down somewhere!
>
> Regards,
>
> Richard Duivenvoorde
>
> On 12/16/21 01:48, Ari Meyer wrote:
> > Hi,
> >
> > We've been trying to use VS Code Python type checkers to reduce errors,
> and leverage Intellisense for code completion.  We've been unable to get
> these to work with PyQGIS and PyQT classes, for instance:
> >
> > image.png
> >
> > I believe I've traced the problem to some customized importing that's
> used in places like the following:
> > c:\OSGeo4W\apps\qgis-ltr\python\qgis\__init__.py
> > c:\OSGeo4W\apps\qgis-ltr\python\qgis\core\__init__.py
> > c:\OSGeo4W\apps\qgis-ltr\python\qgis\PyQt\Qt.py
> >
> > I then found that apparently similar techniques have caused the same
> types of problems when using libraries like TensorFlow:
> >
> https://stackoverflow.com/questions/65271399/vs-code-pylance-pylint-cannot-resolve-import
> <
> https://stackoverflow.com/questions/65271399/vs-code-pylance-pylint-cannot-resolve-import
> >
> > https://github.com/PyCQA/pylint/issues/2603#issuecomment-541622729 <
> https://github.com/PyCQA/pylint/issues/2603#issuecomment-541622729>
> >
> > The convoluted ways suggested to deal with these problems aren't really
> that appealing.  Does anyone have any suggestions for cleaner ways to
> handle this?
> >
> > Are there reasons why QGIS has to be implemented like this?  It's not
> clear from the "monkey patching" comments whether these were temporary
> workarounds or not.
> >
> > Thanks,
> > Ari
> >
> > _______________________________________________
> > Qgis-user mailing list
> > Qgis-user at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20211216/a152f506/attachment.html>


More information about the Qgis-user mailing list