<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:新細明體;
panose-1:2 2 5 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Microsoft YaHei";
panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
{font-family:"\@新細明體";
panose-1:2 1 6 1 0 1 1 1 1 1;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"\@Microsoft YaHei";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Consolas",serif;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi, Zoltan,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks so much for your help.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It is quite helpful. After changing the last line to the directory with Code.exe, it works to open the VS code and can run the Example Python file in section 1.4.1 for the PyQGIS Cookbook (GQIS Testing).
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There are tow lines of information in the terminal window as follows:<o:p></o:p></p>
<p class="MsoNormal">QTemporaryDir: Unable to remove "D:\\Temp\\python-lWnByt" most likely due to the presence of read-only files.<o:p></o:p></p>
<p class="MsoNormal">QTemporaryDir: Unable to remove "D:\\Temp\\python-KrxiSz" most likely due to the presence of read-only files.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any suggestions about it?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards,<o:p></o:p></p>
<p class="MsoNormal">Stephen<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>From:</b> QGIS-User <qgis-user-bounces@lists.osgeo.org> <b>
On Behalf Of </b>Zoltan via QGIS-User<br>
<b>Sent:</b> 2023<span lang="ZH-CN" style="font-family:"Microsoft YaHei",sans-serif">年</span>3<span lang="ZH-CN" style="font-family:"Microsoft YaHei",sans-serif">月</span>13<span lang="ZH-CN" style="font-family:"Microsoft YaHei",sans-serif">日</span> 2:43 PM<br>
<b>To:</b> qgis-user@lists.osgeo.org<br>
<b>Subject:</b> Re: [Qgis-user] How to set PyQGIS imported in VS Code in Windows for a Python file?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:solid windowtext 1.0pt;padding:4.0pt 4.0pt 4.0pt 4.0pt;background:yellow;margin-left:6.0pt;margin-right:6.0pt">
<p style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm;background:yellow;border:none;padding:0cm">
<span style="font-size:9.0pt;font-family:"Microsoft YaHei",sans-serif;color:red">CAUTION:</span><span style="font-size:9.0pt;font-family:"Microsoft YaHei",sans-serif;color:black"> External email. Do not click links or open attachments unless you recognise the
sender and know the content is safe.<br>
</span><span lang="ZH-CN" style="font-size:9.0pt;font-family:"Microsoft YaHei",sans-serif;color:red">警告:</span><span lang="ZH-CN" style="font-size:9.0pt;font-family:"Microsoft YaHei",sans-serif;color:black">外來電郵。 如不認識寄件者,或不確定內容是否安全,切勿按下任何連結或開啟任何附件。</span><span style="font-size:9.0pt;font-family:"Microsoft YaHei",sans-serif;color:black"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt">Hi Li<br>
I am responding because I had a similar experience using PyCharm so below <u>might</u> be useful things for you to check whilst you are waiting for a more informed response:<br>
<br>
Firstly Google using QGIS is VS - there will be a lot of environment variables that will need to be set up.<br>
<br>
I start PyCharm using the following .bat job:<br>
<br>
HTH,<br>
Zoltan</span><o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="font-size:13.5pt">REM <a href="https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-7c8ae188f1d10b08&q=1&e=48d220b7-ed97-45a6-af60-1c568fb25b63&u=https%3A%2F%2Fhaifengniu.com%2Fpost%2Fhow-to-set-environment-for-pyqgis-3-in-pycharm%2F">
https://haifengniu.com/post/how-to-set-environment-for-pyqgis-3-in-pycharm/</a><br>
<br>
REM Setting PyCharm IDE<br>
REM Just double-click pycharm.cmd to start PyCharm. <br>
REM In the settings of PyCharm project, set interpreter as %OSGEO4W_ROOT%\bin\python3.exe<br>
REM In my computer, the full path of interpreter is D:\OSGeo4W64\bin\python3.exe.<br>
<br>
<br>
@echo off<br>
SET OSGEO4W_ROOT=C:\OSGeo4W<br>
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat<br>
REM call "%OSGEO4W_ROOT%"\bin\qt5_env.bat<br>
REM call "%OSGEO4W_ROOT%"\bin\py3_env.bat<br>
call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat<br>
@echo off<br>
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin<br>
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass78\lib<br>
path %PATH%;D:\OSGeo4W64\apps\Qt5\bin<br>
path %PATH%;D:\OSGeo4W64\apps\Python39\Scripts<br>
<br>
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python<br>
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python39<br>
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins<br>
<br>
start "Pycharm Aware of OSGeo4W" /B "C:\\Program Files\\JetBrains\\PyCharm Community Edition 2021.2.2\\bin\\pycharm64.exe"</span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:13.5pt"><br>
<br>
</span><o:p></o:p></p>
<div>
<p class="MsoNormal">On 2023/03/13 09:30, LI, Xin Stephen [MIT] via QGIS-User wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">The OS is Windows 10,<o:p></o:p></p>
<p class="MsoNormal">The QGIS version is 3.28 LTR<o:p></o:p></p>
<p class="MsoNormal">The Python version is 3.11<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The steps following the steps in stection 1.4.1 for the PyQGIS Cookbook (GQIS Testing), i.e.
<a href="https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html#python-applications">
https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html#python-applications</a>
<o:p></o:p></p>
<p class="MsoNormal">The “PAHT” and “PYTHONPYTHON” have been added. <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The problem is: <o:p></o:p></p>
<p class="MsoNormal">When running the Python program file with “import qgis.core”, there is the error
<o:p></o:p></p>
<p class="MsoNormal"><span lang="ZH-CN" style="font-family:"新細明體",serif">“</span>ModuleNotFoundError: No module named 'qgis' ”<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Any suggestions could help modify this setting?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks.<o:p></o:p></p>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>QGIS-User mailing list<o:p></o:p></pre>
<pre><a href="mailto:QGIS-User@lists.osgeo.org">QGIS-User@lists.osgeo.org</a><o:p></o:p></pre>
<pre>List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre>
<pre>Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<pre>-- <o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>=============================================<o:p></o:p></pre>
<pre>Zoltan Szecsei GPrGISc 0031<o:p></o:p></pre>
<pre>Director, Geograph (Pty) Ltd.<o:p></o:p></pre>
<pre>GIS and Photogrammetric Services<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Cape Town, South Africa.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Mobile: +974-5058-8729 (Signal, not WhatsApp)<o:p></o:p></pre>
<pre> +27-83-6004028 (Signal, not WhatsApp)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><a href="https://protect2.fireeye.com/v1/url?k=31323334-501cfaeb-3130cb80-454455535732-fb1c67394740518e&q=1&e=48d220b7-ed97-45a6-af60-1c568fb25b63&u=http%3A%2F%2Fwww.geograph.co.za%2F">www.geograph.co.za</a><o:p></o:p></pre>
<pre>=============================================<o:p></o:p></pre>
</div>
</div>
</body>
</html>