I searched all the same questions, and none of them works for me, so i decided to ask this question in addition to those:
I installed QGIS 2.18 via this downloaded setup 'QGIS-OSGeo4W-2.18.11-1-Setup-x86_64.exe'.
and my PATH system variables are :
C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%PYTHONHOME%;%PYTHONHOME%\Scripts;C:\Program Files\QGIS 2.18\bin;%PATH%
my PATH user variables:
C:\Users\ash\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\ash\AppData\Local\Programs\Python\Python36-32\
PYTHONHOME :
C:\Program Files\QGIS 2.18\apps\Python27
PYTHONPATH :
C:\Program Files\QGIS 2.18\apps\Python27\Lib
*** I use pycharm and my project interpreter is :
Python 2.7.5 (C:\Program Files\QGIS 2.18\bin\python.exe
now if I import qgis.core it will give
import error: no module named qgis.core
error in pycharm, but no errors in qgis python console!!!
What did I do wrong?
-
i forgot to say my operating system is windows 7,2009 build, sp1Ash– Ash2017年09月21日 15:52:09 +00:00Commented Sep 21, 2017 at 15:52
1 Answer 1
I found it, it was just a small tricky approach.
in OsGeo4w website says you have to install QGIS by Osgeo4w setup which it sets all kinds of path variables for you ...
( it was NOT entirely true, in my case)
leave your PATH, Path, PYTHONPATH, PYTHONHOME to where it's functional for all modules unless qgis's.
I removed QGIS standalone and installed QGIS via OsGeo4w however. so the path variables that I wrote in the question must change to the same directories but NOT in QGIS 2.18 ROOT, rather in C:\OSGeo4W64.
for example, my PYTHONHOME is now :
C:\OSGeo4W64\apps\Python27
and so on...
so I created a whatever.cmd file using notepad, with this information in it :
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.3\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-6.4.3\lib
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
set PATH=C:\Program Files\JetBrains\PyCharm Community Edition 2017年1月4日\bin;%PATH%
start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2017年1月4日\bin\pycharm64.exe" %*
and saved it to somewhere.
So if you use Qgis standalone just instead of osgeo_root write your qgis_root directory.
the few last line are dedicated to familiarizing all this mess to Pycharm.
be careful of typing mistakes. I learned, one wrong char can mess it up...
-
1Special thanks to Gary Sherman for awesome information at spatialgalaxy.net/2014/10/09/…Ash– Ash2017年09月21日 15:53:31 +00:00Commented Sep 21, 2017 at 15:53
Explore related questions
See similar questions with these tags.