[QGIS-Developer] PyQGIS unavailable at QGIS startup time on OSGeo4W

Jürgen E. Fischer jef at norbit.de
Wed Oct 2 03:32:21 PDT 2019


Hi Eric,

On Wed, 02. Oct 2019 at 11:32:36 +0200, Eric Lemoine wrote:
> Hi QGIS devs!
> 
> I need to use a PyQGIS startup script (set via the PYQGIS_STARTUP
> envvar). And I want to do "import qgis" from that startup script!
> 
> It works on Linux, because PyQGIS is installed in the system-wide
> Python environment. So no problem here.
> 
> But it doesn't work with OSGeo4W. OSGeo4W installs PyQGIS in
> C:/OSGeo4W64/apps/qgis/python, and that path isn't in sys.path when my
> startup script is executed.
> 
> The C:\OSGeo4W64\bin\qgis-bin.env file indeed does not set PYTHONPATH.
> Likewise, the C:\OSGeo4W64\bin\py3_env.bat file, which
> C:\OSGeo4W64\bin\qgis.bat includes, has "SET PYTHONPATH=" (PYTHONPATH
> set to nothing).
> 
> What do you think? Shouldn't OSGeo4W set PYTHONPATH to
> "%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%" in py3_env.bat and
> qgis-bin.env for startup scripts to be able to import and use the qgis
> module?

No. py3_env.bat belongs to osgeo4w's python and just switches to python3.  It
shouldn't know about qgis.  It's used with everything that use python3 (eg.
several qgis versions).

Not sure why PYQGIS_STARTUP is used that early.  The python path is added
shortly after it was referenced:

https://github.com/qgis/QGIS/blob/master/src/python/qgspythonutilsimpl.cpp#L98

So other platforms should have the same issue.


Jürgen

-- 
Jürgen E. Fischer           norBIT GmbH             Tel. +49-4931-918175-31
Dipl.-Inf. (FH)             Rheinstraße 13          Fax. +49-4931-918175-50
Software Engineer           D-26506 Norden            https://www.norbit.de
QGIS release manager (PSC)  Germany                    IRC: jef on FreeNode
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20191002/8608265b/attachment.sig>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Pflichtangaben
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20191002/8608265b/attachment.ksh>


More information about the QGIS-Developer mailing list