TransWikia.com

No Module named qgis

Geographic Information Systems Asked by user32496 on May 19, 2021

I installed QGIS through OSGeo4W, and I am trying to write a standalone PyQGIS script, however, I am unable to import the qgis, qgis.core, processing ect… modules, as shown in the picture, I get the ‘Import Error: No Module named qgis…

enter image description here

I sought help from the many examples that exist that require you to change your command line path to your python libraries, change your python path to your c:OSGeo4Wappsqgispython ect…

Here is a list of the answers I tried, but, it seems myself and many others are still unable to fix this issue, as I could not get it to acknowledge the existence of those libraries:

Problem with import qgis.core when writing a stand-alone PyQGIS script:

Cannot run standalone QGIS script

Running Custom Applications:

3 Answers

I am running a batch file first.

call "C:OSGeo4W64bino4w_env.bat"
set PATH=%PATH%;C:OSGeo4W64appsqgisbin

Correct answer by okorkut on May 19, 2021

Here is how I solved the issue, it’s a bit of work, but you can now import the modules without hassle, I created a Python Script, that uses the module subprocess, to write an osgeo4w command called ‘python-qgis’ Its nothing complicated, here it is
enter image description here

I called it NotePadPlus.py (No real reason for calling it that) I then call this script from the osgeo4w command shell

enter image description here

And now I am able to call the qgis module without any issue! And just to show its not just pretending to accept it I misspelled the Tkinter module and it says it does not exist enter image description here

I hope this helps, and you can adapt it to suit your needs!

Answered by user32496 on May 19, 2021

Here is probably the best solution I have found, it has made very easy thanks to http://www.qgistutorials.com/en/docs/running_qgis_jobs.html.

First thing you need to do is create a batch file, call it "launch", and enter the following enter image description here

Then you create your GIS Standalone Python script, hopefully, this is more complex than mine, but this is just to show you that the modules import correctly.

enter image description here

Then all you need to do is trigger the launch batch file( I just double clicked mine) and it will import the modules without issue!

enter image description here

Answered by user32496 on May 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP