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

Richard Duivenvoorde rdmailings at duif.net
Wed Dec 15 23:30:20 PST 2021


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



More information about the Qgis-user mailing list