[Qgis-user] How to set PyQGIS imported in VS Code in Windows for a Python file?

Zoltan zoltans at geograph.co.za
Sun Mar 12 23:42:58 PDT 2023


Hi Li
I am responding because I had a similar experience using PyCharm so 
below _might_ be useful things for you to check whilst you are waiting 
for a more informed response:

Firstly Google using QGIS is VS - there will be a lot of environment 
variables that will need to be set up.

I start PyCharm using the following .bat job:

HTH,
Zoltan

    REM
    https://haifengniu.com/post/how-to-set-environment-for-pyqgis-3-in-pycharm/

    REM Setting PyCharm IDE
    REM Just double-click pycharm.cmd to start PyCharm.
    REM In the settings of PyCharm project, set interpreter as
    %OSGEO4W_ROOT%\bin\python3.exe
    REM In my computer, the full path of interpreter is
    D:\OSGeo4W64\bin\python3.exe.


    @echo off
         SET OSGEO4W_ROOT=C:\OSGeo4W
         call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
    REM call "%OSGEO4W_ROOT%"\bin\qt5_env.bat
    REM call "%OSGEO4W_ROOT%"\bin\py3_env.bat
         call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat
         @echo off
         path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
         path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass78\lib
         path %PATH%;D:\OSGeo4W64\apps\Qt5\bin
         path %PATH%;D:\OSGeo4W64\apps\Python39\Scripts

         set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
         set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python39
         set
    QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

    start "Pycharm Aware of OSGeo4W" /B "C:\\Program
    Files\\JetBrains\\PyCharm Community Edition
    2021.2.2\\bin\\pycharm64.exe"




On 2023/03/13 09:30, LI, Xin Stephen [MIT] via QGIS-User wrote:
>
> The OS is Windows 10,
>
> The QGIS version is 3.28 LTR
>
> The Python version is 3.11
>
> The steps following the steps in stection 1.4.1 for the PyQGIS 
> Cookbook (GQIS Testing), i.e. 
> https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html#python-applications 
>
>
> The “PAHT” and “PYTHONPYTHON” have been added.
>
> The problem is:
>
> When  running the Python program file with “import qgis.core”, there 
> is the error
>
> “ModuleNotFoundError: No module named 'qgis' ”
>
> Moreover, after reinstalling the Python 3.9.5 as the QGIS related, 
> then run the Python file in VS Code by Python 3.9.5, the Error is the 
> same.
>
> Any suggestions could help modify this setting?
>
> Thanks.
>
>
> _______________________________________________
> 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

-- 

=============================================
Zoltan Szecsei GPrGISc 0031
Director, Geograph (Pty) Ltd.
GIS and Photogrammetric Services

Cape Town, South Africa.

Mobile: +974-5058-8729 (Signal, not WhatsApp)
         +27-83-6004028 (Signal, not WhatsApp)

www.geograph.co.za
=============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230313/3730a8b9/attachment.htm>


More information about the QGIS-User mailing list