Title: No Module named qgis
Tags: qgis;pyqgis;python-2.7;osgeo4w
Question: 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... 



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:\OSGeo4W\apps\qgis\python 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: 


Here is the accepted answer: I am running a batch file first.

```call "C:\OSGeo4W64\bin\o4w_env.bat"
set PATH=%PATH%;C:\OSGeo4W64\apps\qgis\bin
```

Comment for this answer: Fantastic you found your own solution, am sure this will help others
Comment for this answer: I tried to use this method as it is much easier than mine, but, I still get Import error: No Module named QGIS @okorkut
Comment for this answer: Have you verified the path of the "o4w_env.bat" in your computer. I set this according to my path. I assumed that since you installed through QSGeo4W file paths should be similar. May be your file installed in a different directory.

Here is another answer: 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


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.



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!




Here is another answer: 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


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



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
 

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

Comment for this answer: Couldn't you just call `python-qgis` from the osgeo4w shell (whithout the python subprocess wrapper script)?
Comment for this answer: yes you can! what I have done is created an entire python script that does various tasks, and at the start the subprocess calls the python-qgis, and this then allows the qgis and other modules to be called in the rest of that same script

{'source': 'StackExchangeDataset', 'subset': 'gis.stackexchange.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:06/30/16', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<qgis><pyqgis><python-2.7><osgeo4w>', 'Title': 'No Module named qgis', 'ViewCount': 5036, 'id': 200510, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}