12

I wanted to set up PyCharm the way this blog post explains: Setting up PyCharm for PyQGIS and Qt.

I did everything as instructed but when it comes to adding project interpreters I got this error message:

Pycharm

Does anyone have a solution to this?

mgri
  • 16,159
  • 6
  • 47
  • 80
Krzysztof Żuraw
  • 177
  • 1
  • 2
  • 7

4 Answers4

3

From the comments it looked like the asker of this question was able to resolve their problem by reading a blog posting entitled A Quick Guide to Getting Started With PyQGIS on Windows.

In that blog the advice offered seemed to be:

We only changed the last line, adding the start statement with the path to the IDE (PyCharm). If you save this to something like pycharm.cmd, you can double-click on it to start PyCharm. The same method works for other IDEs, such as PyDev.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
3

The batch script from the A Quick Guide to Getting Started with PyQGIS on Windows as described in the comments and by @PolyGeo maybe outdated. The SDK seems invalid appear in PyCharm 2016.3 by using the script.

I suspect it needs more paths to be included especially (maybe) pip.exe path that exist in %OSGEO4W_ROOT%\apps\Python27\Scripts. So I include that and all other paths (not sure which one is required, maybe some unnecessary, but no time to test 1 by 1):

@echo off

SET OSGEO4W_ROOT=C:\Program Files\QGIS 2.18
SET PYCHARM="C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\bin\pycharm.exe"

CALL %OSGEO4W_ROOT%\bin\o4w_env.bat
CALL %OSGEO4W_ROOT%\apps\grass\grass-7.0.5\etc\env.bat

path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.0.5\lib

SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\bin
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Scripts
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages
SET PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\DLLs
SET QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "PyCharm aware of QGIS" /B %PYCHARM% %*

Then it works. Edit the paths to match your environment.

Anyway, the recent how python/conda installation register PATH or PYTHONPATH in my environment, I follow the same for QGIS python paths in the script.

CallMeLaNN
  • 337
  • 1
  • 8
0

I had the same issue: I clicked on "file/Reload all from disk", it works ...

-1

Make sure that the interpreter python.exe is executable if you're on Linux.

PyCharm will show the same error even if interpreter has been set up fine.

whyzar
  • 12,053
  • 23
  • 38
  • 72