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

LI, Xin Stephen [MIT] stephenli at eduhk.hk
Mon Mar 13 23:13:44 PDT 2023


Hi, Sylvain,

Thanks for your suggestions.

Is the  qgis-bin.env file  in the GQIS/bin dir?

It includes
PATH=C:\OSGeo4W\apps\qgis\bin;


From: PIERRE Sylvain <sylvain.pierre at alsace.eu>
Sent: 2023年3月13日 4:03 PM
To: PIERRE Sylvain <sylvain.pierre at alsace.eu>; LI, Xin Stephen [MIT] <stephenli at eduhk.hk>
Cc: qgis-user at lists.osgeo.org
Subject: RE: How to set PyQGIS imported in VS Code in Windows for a Python file?


CAUTION: External email. Do not click links or open attachments unless you recognise the sender and know the content is safe.
警告:外來電郵。 如不認識寄件者,或不確定內容是否安全,切勿按下任何連結或開啟任何附件。
Oops ! it’s in .env file and it looks like this for me :

PATH=$PATH;"C:\Program Files\QGIS 3.16.16\bin\";"C:\Program Files\QGIS 3.16.16\apps\qgis\bin"
PYTHONPATH="C:\Program Files\QGIS 3.16.16\apps\qgis\python"
PYTHON_VERSION=Python39

[cid:image005.jpg at 01D9567D.5045C230]
Sylvain PIERRE
Chef de projet système d’information
Direction des Systèmes d’Information et du Développement Numérique
Service Projets et Ingénierie Numérique
Collectivité européenne d’Alsace
Tél : 03 88 76 68 88
sylvain.pierre at alsace.eu<mailto:sylvain.pierre at alsace.eu>
www.alsace.eu<https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-c7ed558dc3d755a3&q=1&e=4861685e-e8b2-49a8-9282-17cb5134c3f5&u=http%3A%2F%2Fwww.alsace.eu%2F>
[facebook]<https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-9ee20224e4c9d4f6&q=1&e=4861685e-e8b2-49a8-9282-17cb5134c3f5&u=http%3A%2F%2Fwww.facebook.com%2Ftoutelalsace> [twitter] <http://www.twitter.com/toutelalsace>  [insta] <http://www.instagram.com/toutelalsace>

De : QGIS-User <qgis-user-bounces at lists.osgeo.org<mailto:qgis-user-bounces at lists.osgeo.org>> De la part de PIERRE Sylvain via QGIS-User
Envoyé : lundi 13 mars 2023 08:56
À : LI, Xin Stephen [MIT] <stephenli at eduhk.hk<mailto:stephenli at eduhk.hk>>
Cc : qgis-user at lists.osgeo.org<mailto:qgis-user at lists.osgeo.org>
Objet : Re: [Qgis-user] How to set PyQGIS imported in VS Code in Windows for a Python file?

Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
• Assurez-vous d’abord qu’il ne s’agit pas d’un email malveillant avant de cliquer sur tout lien ou pièce jointe.
Apprendre à reconnaître un email de phishing.<https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-28bef29d5316aeb1&q=1&e=4861685e-e8b2-49a8-9282-17cb5134c3f5&u=https%3A%2F%2Fintranet.alsace.eu%2Factualites%2Fapprenez-a-reconnaitre-un-email-phishing%2F>
Hi,

Did you set these variable in env file in your user .vscode dir ?


De : QGIS-User <qgis-user-bounces at lists.osgeo.org<mailto:qgis-user-bounces at lists.osgeo.org>> De la part de LI, Xin Stephen [MIT] via QGIS-User
Envoyé : lundi 13 mars 2023 07:30
À : qgis-user at lists.osgeo.org<mailto:qgis-user at lists.osgeo.org>
Objet : [Qgis-user] How to set PyQGIS imported in VS Code in Windows for a Python file?

Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
• Assurez-vous d’abord qu’il ne s’agit pas d’un email malveillant avant de cliquer sur tout lien ou pièce jointe.
Apprendre à reconnaître un email de phishing.<https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-28bef29d5316aeb1&q=1&e=4861685e-e8b2-49a8-9282-17cb5134c3f5&u=https%3A%2F%2Fintranet.alsace.eu%2Factualites%2Fapprenez-a-reconnaitre-un-email-phishing%2F>
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230314/1f65f250/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.jpg
Type: image/jpeg
Size: 5564 bytes
Desc: image005.jpg
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230314/1f65f250/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.png
Type: image/png
Size: 699 bytes
Desc: image007.png
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230314/1f65f250/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image009.png
Type: image/png
Size: 713 bytes
Desc: image009.png
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230314/1f65f250/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image011.png
Type: image/png
Size: 815 bytes
Desc: image011.png
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230314/1f65f250/attachment-0005.png>


More information about the QGIS-User mailing list