2

I want to develop a plugin gor QGIS3. I downloaded Osgeo4w network installer 64Bit. I created a bat file as following for set my environment variables;

@echo off
call "%~dp0\o4w_env.bat"
call qt5_env.bat
call py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
start "QGIS" /B "%OSGEO4W_ROOT%\bin\qgis-bin.exe" %*
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 
2018.2.5\bin\pycharm.exe"
start "PyCharm aware of QGIS" /B %PYCHARM% %*

But when I try to add interpreter to my project in pycharm it gives the following error:

enter image description here

What am I doing wrong? When I try sys.path from QGIS3 console it gives the path like this :

enter image description here

I read about this situation from other posts but they did not solve my problem.

  • your batch is a mess and has a lot of errors ;-) Please take look into the osgeo bin directory. There is a batch/template file to call python with the qgis environnent. Make a copy of it and change the last line to start pycharm. – Andreas Müller Nov 16 '18 at 11:14
  • Thank you for helpful comment. I did what you said and solved python error but now pycharm does not recognize qgis classes. I edited batch file in the question. – user51044 Nov 16 '18 at 19:27
0

One way you can configure environment variables in PyCharm is as follows:

  1. Go to Settings
  2. Go to the Project interpreter option
  3. Click on the button whose icon is a gear and select the option Show All...
  4. A Project Interpreters window will appear and you must click on the button (Show paths for the selected interpreter).
  5. A Interpreter Paths window will be displayed and you must click on the (Add) button to include your environment variables.

Once your environment variables are registered you can accept the changes made.

enter image description here

0

This is my approach:

  1. Please take look into the osgeo bin directory. There is a batch/template file to call python with the qgis environnent. Make a copy of it and change the last line to start pycharm.
  2. Don't know if that makes a difference, but i call the bat file in pycharms bin: SET PYCHARM="%~dp0\bin\pycharm.bat" instaed of the exe.
  3. You should try to create a new project in pycharm, choosing "Existing interpreter", then click the little icon "Add local" and choose System Interpreter on the left and osgeo's python interpreter python.exe on the right. In my case it is under osgeo4w\apps\python36\python.exe. I also copied python3.dll and python36.dll from the bin directory into apps\python36, some ide's need this, don't sure about pycharm...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.