I'm trying to create a PyQGIS standalone script in windows 10 but I have some errors.

First I have read this post and I follow comment of Mr. @caiohamamura but I have semi-success I think, and I don't why happen this error.

first :

Your PYTHONHOME should be:


Your PATH should include (in the beggining):

C:\OSGeo4W64\bin; C:\OSGeo4W64\apps\qgis-ltr-dev\bin 

PYTHONPATH should have:


and finally the test.

Python in cmd prompt:


Python in OSGeo shell :


Why in OSGeo shell I take this error :

ImportError: DLL load failed: ─ίΊ ▐ΪάΊ ϊΫΊάΪⁿ Ίά ίΊΪΎΏώ≤Ϊί▀ ύ ΆάϋΎ±ώ≤Ή▌Ίύ ΈίώΪ.

What am I doing wrong? What is the difference?

1 Answer 1


You're not doing anything wrong, the issue is 100% with the fact that for each version of Python you run (out of each shell), they are calling on different paths for dependencies. OSGeo4W shell starts with its own dependencies that are sourced in the installation folder, and will be completely different from what you have manually added to your PYTHONPATH variable. To see this, input the following into OSGeo4W shell in Python:

import sys

That will show you probably that the dependencies don't include those qgis-ltr-dev build paths you manually included to your system environments. This gets tricky, and QGIS has it segmented because they provide a number of different versions/builds with each install.

If you need to run your pyQgs scripts from the OSGeo4W shell, you'll need to include calls for sys.path.append() for each of the desired qgis-ltr-dev paths.

But a much easier way is to use the following shell, which references by default all the right dependencies in this build:


If you want to permanently incorporate these paths into OSGeo4W shell, edit the file "C:\OSGeo4W64\OSGeo4W.bat" to look like this:

@echo off
rem Root OSGEO4W home dir to the same directory this script exists in
call "%~dp0\bin\python-qgis-ltr-dev.bat"

rem List available o4w programs
rem but only if osgeo4w called without parameters
@echo on
@if [%1]==[] (echo run o-help for a list of available commands & cmd.exe /k) else (cmd /c "%*")

This will open you up into a Python command prompt, but if you enter "quit()", you should be then able to run your scripts "python myscript.py" with your imported qgis.core functions. Here is an image of how that works: enter image description here

  • first thank you for response,second in the print sys.path all paths is the some with only deference is on cmd is name start with C:\\OSGeo4W64 and in osgeo shell is C:\\OSGEO4~1 but i dont think if is wrong...third i dont have other python in my system i use olny with QGIS python..finally if i use C:\OSGeo4W64\bin\python-qgis-ltr-dev.bat then start python and i can import qgis.core .but i need more automate way from to call any time this .bat. how to do this permanent like is in cmd now ?
    – hellas
    Commented Nov 9, 2017 at 19:26
  • 1
    See my edit above
    – AlecZ
    Commented Nov 9, 2017 at 20:00
  • yes that work but i dont need this,now i have only one option to use just python..i cant use cd .. pip install and other options of shell command or python myscript.py and more.that i need only if i select python way in osgeo shell to dont keep qgis import errors like windows cmd.exe
    – hellas
    Commented Nov 9, 2017 at 20:35
  • 1
    No those options are there - it will open directly to the Python ">>>" command line, but if you type: quit(), click enter, you will be at command line, but will be able to reference the correct Python install and Paths that you want to. Fore example, you can open OSGeo4W shell, type "quit()", then type "pip --version" and it should come up fine. Also, if you run a python script now("python myscript.py"), it'll have all the correct qgis-ltr-dev paths.
    – AlecZ
    Commented Nov 9, 2017 at 21:39
  • after quit() if i type :python (again) and i try to import qgis mudules then all modules work correct ot i loose the path and again the some error ?you are very good that all is very important
    – hellas
    Commented Nov 9, 2017 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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