[osgeo4w-dev] [osgeo4w] #853: Broken venv created with python-qgis.bat

OSGeo4W trac_osgeo4w at osgeo.org
Wed Sep 18 07:17:00 PDT 2024


#853: Broken venv created with python-qgis.bat
----------------------+---------------------------
Reporter:  nicogodet  |      Owner:  osgeo4w-dev@…
    Type:  defect     |     Status:  new
Priority:  normal     |  Component:  Package
 Version:             |   Keywords:
----------------------+---------------------------
 I spent some times searching for the best way to create an environnement
 for VSCode with proper linting, etc...

 Best way I found is to create a venv using `python-qgis.bat`.

 {{{
 C:\OSGeo4W\bin\python-qgis.bat -m venv --system-site-packages .venv
 }}}
 It requieres few extra steps (won't describe here as irrelevant).

 The issue is inside the `.venv\pyvenv.cfg` file created.
 According to [https://peps.python.org/pep-0405/#specification PEP 405],
 this file is read and used to set a bunch of variables including
 `PYTHONHOME`.

 Content of created file:
 {{{
 home = C:\OSGeo4W\bin
 include-system-site-packages = true
 version = 3.12.6
 executable = C:\OSGeo4W\bin\python.exe
 command = C:\OSGeo4W\bin\python.exe -m venv --system-site-packages
 D:\Desktop\temp\.venv
 }}}

 Activate venv and start python.

 {{{
 >.venv\Scripts\activate.bat

 (.venv) D:\Desktop\temp>python
 Could not find platform independent libraries <prefix>
 Python 3.12.6 (main, Sep  7 2024, 18:59:42) [MSC v.1938 64 bit (AMD64)] on
 win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>>

 }}}

 Notice this line: `Could not find platform independent libraries <prefix>`

 Deactivate and alter `.venv\pyvenv.cfg`:

 {{{
 home = C:\OSGeo4W\apps\Python312
 include-system-site-packages = true
 version = 3.12.6
 executable = C:\OSGeo4W\apps\Python312\python.exe
 command = C:\OSGeo4W\apps\Python312\python.exe -m venv --system-site-
 packages D:\Desktop\temp\.venv
 }}}


 {{{
 (.venv) D:\Desktop\temp>deactivate

 [...] Alter .venv\pyvenv.cfg

 D:\Desktop\temp>.venv\Scripts\activate.bat

 (.venv) D:\Desktop\temp>python
 Python 3.12.6 (main, Sep  7 2024, 18:59:42) [MSC v.1938 64 bit (AMD64)] on
 win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>>
 }}}

 See, no more `Could not find platform independent libraries <prefix>`.

 The root cause is that `python-qgis.bat` call python exe which is in
 `C:\OSGeo4W\bin` instead of calling the right exe in
 `C:\OSGeo4W\apps\Python312` where `Lib`, `libs`, `include`, `Scripts`, ...
 folders are.
-- 
Ticket URL: <https://trac.osgeo.org/osgeo4w/ticket/853>
OSGeo4W <http://trac.osgeo.org/osgeo4w>
OSGeo4W is the Windows installer and package environment for the OSGeo stack.


More information about the osgeo4w-dev mailing list