[QGIS-Developer] import 3d or _3d in python?
Raymond Nijssen
r.nijssen at terglobo.nl
Tue Oct 4 00:50:42 PDT 2022
Done:
https://github.com/qgis/pyqgis/issues/97
Raymond
On 03-10-2022 10:24, Martin Dobias wrote:
> Hi Raymond
>
> The general idea is that for every PyQGIS module (e.g. "core") there is
> a compiled python module (e.g. _core.so) and a directory acting as a
> module ("core") which imports the compiled module and adds some extra
> functionality (docstrings and more). So normally one wants to use import
> qgis.core instead of qgis._core.
>
> Now with the 3d module things are not so great, because "3d" is not a
> valid module name because of the leading digit, so import qgis.3d simply
> won't work. There are some ways to work it around [1], but I wouldn't
> recommend using them. But as stated earlier, importing qgis._3d should
> generally do the job.
>
> It is probably worth creating a ticket to address this, but I am not
> sure how to best fix it - probably the whole module should be renamed so
> avoid the leading digit - e.g. "threed"
>
> [1]
> https://stackoverflow.com/questions/9090079/in-python-how-to-import-filename-starts-with-a-number
> <https://stackoverflow.com/questions/9090079/in-python-how-to-import-filename-starts-with-a-number>
>
> Cheers
> Martin
>
>
> On Mon, Oct 3, 2022 at 8:58 AM Raymond Nijssen via QGIS-Developer
> <qgis-developer at lists.osgeo.org <mailto:qgis-developer at lists.osgeo.org>>
> wrote:
>
>
> While trying to import a 3D class in a python script, I found out that
> the code in the pyqgis docs is not working (for me):
>
> from qgis.3d import QgsLayoutItem3DMap
>
>
> Instead I need to add an underscore for the 3d module name:
>
> from qgis._3d import QgsLayoutItem3DMap
>
>
>
> Should this be fixed in the documentation? I'm not all sure, cause when
> trying to fix it, I found this related commit:
>
> https://github.com/qgis/pyqgis/commit/1ac564790aa0b7abbd003c04d07358d8e4f14493
> <https://github.com/qgis/pyqgis/commit/1ac564790aa0b7abbd003c04d07358d8e4f14493>
>
>
>
> This is the page in the docs:
> https://qgis.org/pyqgis/master/3d/QgsLayoutItem3DMap.html
> <https://qgis.org/pyqgis/master/3d/QgsLayoutItem3DMap.html>
>
>
> Should I make an issue? It took me a while to figure out that _3d
> solution.
>
> Cheers,
> Raymond
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org <mailto:QGIS-Developer at lists.osgeo.org>
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
>
More information about the QGIS-Developer
mailing list