qgis / qgis4.0_api

Tracker for QGIS 4.0 API related issues and developer discussion
3 stars 1 forks source link

PyQGIS bootstrap is complicated #9

Open wonder-sk opened 8 years ago

wonder-sk commented 8 years ago

Currently loading PyQGIS from outside QGIS is more complicated than it should be. There is QgsApplication.init(), QgsApplication.initQgis() for initialization (can you tell the difference? :-) ), the path(s) can be set via QgsApplication.setPrefixPath() or via env.variable QGIS_PREFIX_PATH.

Ideally users should not need to call anything extra, just do import qgis.core (and also QgsApplication.exitQgis() should be called automatically).

QgsApplication probably should not be derived from QApplication and the Q[Core|Gui|-]Application creation should be left up to the client.

PyQGIS should be installed in the system to python's site packages path, so it is not necessary to setup PYTHONPATH in order to import it.

wonder-sk commented 8 years ago

One thing that could help would be to put all the pieces required for qgis_core bootstrap directly into the library. This currently includes:

Including those directly in qgis_core would not require setting any extra paths and may also speed up the load if providers are not loaded from external modules. GDAL installs for example typically bundle all the basic drivers in the library.

timlinux commented 8 years ago

Hi

I like the sentiment, but I do wonder about putting PyQGIS in the system path:

PyQGIS should be installed in the system to python's site packages path, so it is not necessary to setup PYTHONPATH in order to import it.

I have about 6 different versions of QGIS installed and I like to be able to switch between them. Don't linux etc packages already go into the sys path? And don't we already have a flag to indicate whether python libs should go into the system site-packages dir?

wonder-sk commented 8 years ago

I have about 6 different versions of QGIS installed and I like to be able to switch between them. Don't linux etc packages already go into the sys path? And don't we already have a flag to indicate whether python libs should go into the system site-packages dir?

Same here with different versions :) It's true there is a switch to install bindings globally. I guess I mainly thought such option could be on by default if installing to standard locations such as /usr or /usr/local. Agreed it should not be forced for custom installs. I see e.g. debian packages do the global install, but not osgeo4w and not sure about os x builds.

timlinux commented 8 years ago

I guess I mainly thought such option could be on by default if installing to standard locations such as /usr or /usr/local.

Yeah I guess that makes good sense :+1:

NathanW2 commented 8 years ago

PyQGIS should be installed in the system to python's site packages path, so it is not necessary to setup PYTHONPATH in order to import it.

No system Python on Windows. Also I think we do this so that we can have different versions of QGIS installed. \o/ for standards!